Functions

Does anyone know what is these codes trying to do?
And what are the mistakes in it?


#include<stdio.h>

int f(int x, int y);

int main()
{
int x, y, results;
x=3;
y=4;
results=f(x,y);
x=f(y, result+x);
y=f(1, f(results,2) );
return 0;
}

int f( int x, int y)
{
return x*x + y*y;
}
just put the letter "s" to the word results>>>x=f(y, result+x);

& u will have no error
hi thanks.
can i know what is this codes trying to do?
and there is no output?
it's a simple example of funcs

there's no output coz there's no cout operation

try to put -

printf("%d",x); for example

This code includes header file.
#include<stdio.h>

http://pubs.opengroup.org/onlinepubs/7908799/xsh/stdio.h.html


1
2
3
4
5
6
7
8
9
10
int main()
{
int x, y, results;
x=3;
y=4;
results=f(x,y);
x=f(y, result+x);
y=f(1, f(results,2) );
return 0;
} 


this is your main function.

Last edited on
reply, I just realized I missed a lot of code in there. I'm going to edit some of that out, and just leave in what I know is right, so you don't get messed up.
I wanted to take another crack at it, but being a newb it's hard for me to decipher. I know someone that could do it, if they could find the time, and had the patience ;).

here's my second take.

#include<stdio.h>

includes header file

int f(int x, int y);

this to me looks like the declaration of a function, but I'm not sure. It looks weird because because it doesn't have a body of code to run between curly brackets. Someone with more experience is going to have to touch on that one.

1
2
3
4
int x, y, results;
x=3;
y=4;
results=f(x,y);


declares variables x,y, and results
it gives x the value of 3, y the value of 4, and results the value of called function f.

x=f(y, result+x);

this gives x the value of called function f after it calculates.



y=f(1, f(results,2) );

this gives y the value of called function f after it calculates with passed arguments 1, f(results,2)

return 0;

this is the functions return value. 0 is usually used for void functions, as far as I know.

}

1
2
3
4
int f( int x, int y)
{
return x*x + y*y;
}


to me this looks like the declaration of function f.
it returns the value of x times x plus y times y.

the order of precedence is

brackets, exponents, dividing, multiplying, adding, and subtracting.

sense there's only multiplying, and adding. it would multiply first, and then add.

so answer for x time x would be added to the answer of y times y...

what this program does I have no idea...but I can tell you by the looks of it it doesn't do much useful, lol.
Last edited on
there's no user input for anything, so I'm thinking, if it runs at all...it just calculates based on some computer stuff, plus what variables are given values.
Thank you for taking your time to explain!
Yup i guess this program is just a sample and not much of use. Haha
Thanks once again :)
Topic archived. No new replies allowed.