Quote (Eep @ Oct 15 2012 07:50am)
Int f(int a, int b, intc) this not only declares functions, but also says you are passing it arguments.
So c=f(a+b, a+c, b+c) will pass the function f three values.
In the function f, a will now be a+b and so on.
Functions can return values as well. You can tell what they return by how they were defined.
Ie, int f or string s etc. yours is int, so it should return an int.
Also, you have some constants in your code that were never defined (B)
Not sure how they went from lower to upper but that happened while copying.
So for example I want to start by doing
Code
c = f(a+b, a+c, b+c);
c = f(5,3,4);
int f(int a, int b, int c) (with a=5,b=3,c=4)
sum = 12;
sum < a*b;
return a+b(8) to c value
a=2, b=3, c=8.
I got this part to print correctly
Now I do
Code
b= f(a,b,c);
b= f(2,3,8);
int f(int a, int b, int c) (with a=2,b=3,c=8)
sum 13
sum !< a*b
sum !< 2*a*b
return a+c(10) to b value
a=2,b=10,c=8
Finally
Code
a = f( a, b, f(c, b, a) );
a = f( 2, 10, f(8, 10, 2) );
f(8,10,2)
sum= 20
20 < 80
return a+b(18) into f(c)
a = f(2,10,18)
sum = 30
sum !< 20
sum < 2*20
return b+c(28) into a value
a=28,b=10,c=18
Now that I know the functions retain their values, I got the correct output, it seems. What makes it so that the values are retained? Previously I thought that after every evaluation of these functions:
Code
b = f(a, b, c);
c = f(a+b, a+c, b+c);
a = f( a, b, f(c, b, a) );
the variables in the next f() -a,b,c would get their values from:
int a = 2, b = 3, c = 1;
your explanation was very helpful though. I'm missing some background information on functions clearly- but that was a big step forward..
This post was edited by TheDiscoveryChannel on Oct 15 2012 10:22am