• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

HELP WITH CS HW (C programming)

Aznguy1872

Senior member
This stuff is probably very easy for you guys, its computer science 151, so basic stuff. I am having trouble with the following questions. Any help would be great.

1. If called by the statement n = myFun(7); what value will be assignmented to n?
int myFun(int val) {
return (val * val)/2;
}

2. Given the function definition shown for f1() below, what will be printed?
int f1(int val);
int main(void) {
int n = 1;
printf("%d", f1(n));
printf("%d", f1(n));
printf("%d", f1(n));
return;
}

int f1(int val) {
return ++val;
}

3. Given the function definition shown for f1() below, what will be printed?
int f1(int);
int main(void) {
int val = 5;
printf("%d", f1(val++));
printf("%d", f1(val++));
printf("%d", f1(val++));
return;
}

int f1(int val) {
return --val;
}

Thanks alot!
 
Wow, you don't even know how to compile C code? You might want to try learning this stuff or else you'll end up studying micro-economics.

Serously, learn this stuff.

<== software engineer
 
Yea, I am just running out of time. I had two midterms already and have lots to do. If I had the time I would learn it right now. I guess I could just compile it and find out the 2nd one, but for some reason the window pops up fast then dissappears right afterwards. I added a "getchar" but that still goes away... help please.
 
OH,i am very bad at programming but better at the other stuff. Like problem solving and crap. Just I dislike programming, I give peeps that can do it props.
 
Originally posted by: Aznguy1872
OH,i am very bad at programming but better at the other stuff. Like problem solving and crap. Just I dislike programming, I give peeps that can do it props.

You have a problem right here 😀
 
Originally posted by: screw3d
Originally posted by: Aznguy1872
OH,i am very bad at programming but better at the other stuff. Like problem solving and crap. Just I dislike programming, I give peeps that can do it props.

You have a problem right here 😀

Owned!
 
Compile your program and run it from the command line (in Windows: Start->Run->cmd). You should see the output from statements like printf in that window. Otherwise you get the window popping up then closing real quick.
 
Originally posted by: Aznguy1872
This stuff is probably very easy for you guys, its computer science 151, so basic stuff. I am having trouble with the following questions. Any help would be great.

1. If called by the statement n = myFun(7); what value will be assignmented to n?
int myFun(int val) {
return (val * val)/2;
}

24

2. Given the function definition shown for f1() below, what will be printed?
int f1(int val);
int main(void) {
int n = 1;
printf("%d", f1(n));
printf("%d", f1(n));
printf("%d", f1(n));
return;
}

int f1(int val) {
return ++val;
}

222
There is probably a typo in there, I don't think the compiler is going to be happy when there is no return value while it is expecting an int.

3. Given the function definition shown for f1() below, what will be printed?
int f1(int);
int main(void) {
int val = 5;
printf("%d", f1(val++));
printf("%d", f1(val++));
printf("%d", f1(val++));
return;
}

int f1(int val) {
return --val;
}

456
Don't think it's going to compile for the same reason as above.

Thanks alot!

 
toattett. Hey Thank you very much for your help, I was able to do the other 7 pbs but just had trouble with these. Thank you
 
Originally posted by: Aznguy1872
toattett. Hey Thank you very much for your help, I was able to do the other 7 pbs but just had trouble with these. Thank you
Why are you thanking him? He just stopped you from learning.
 
Originally posted by: kamper
Originally posted by: Aznguy1872
toattett. Hey Thank you very much for your help, I was able to do the other 7 pbs but just had trouble with these. Thank you
Why are you thanking him? He just stopped you from learning.

Thanks, our company will probably hire him.
 
Back
Top