1. ## Question about Recursive Functions

Show the exact screen-output of each of the following programs:

c)

Code:
```#include <stdio.h>
int f (int a)
{
if (a== 1)
return 1;
else if (a==2)
return 3;
else
return (f(a-1) + f(a-2));
} //end of function
void main ()
{
int n;
printf ("Enter n:\n");
scanf ("%d", &n);
printf("%d", f(n));
}```
Hint: Assume entered value of n = 6

===========================================

Code:
```#include<stdio.h>

int myfunction(int p, int q)

{

if (p == q)

return p;

else if (p < q)

return myfunction(q - p, p);

else

return myfunction(p - q, q);

}

void main()

{

int result;

result=myfunction(20,4);

printf("%d",result);

}```

my question is how to get the answer????

2. > void main ()
main returns an int - see the FAQ

Also learn how to indent code with some consistency. All this "to the left" indentation is much too difficult to follow.

> my question is how to get the answer?
You mean other than running it?

3. Originally Posted by jack999
Show the exact screen-output of each of the following programs:

c)

Code:
```#include <stdio.h>
int f (int a)
{
if (a== 1)
return 1;
else if (a==2)
return 3;
else
return (f(a-1) + f(a-2));
} //end of function
void main ()
{
int n;
printf ("Enter n:\n");
scanf ("%d", &n);
printf("%d", f(n));
}```
Hint: Assume entered value of n = 6

Code:
```f(6) =
f(5)                             + f(4) =
f(4)               + f(3)        + f(3)        + f(2) =
f(3)        + f(2) + f(2) + f(1) + f(2) + f(1) +   3 =
f(2) + f(1) +   3  +   3  +   1  +   3  +   1  +   3 =
3  +   1  +   3  +   3  +   1  +   3  +   1  +   3 =

18```
See if you can answer the other one now.

4. Code:
```f(6) =
f(5)                             + f(4) =
f(4)               + f(3)        + f(3)        + f(2) =
f(3)        + f(2) + f(2) + f(1) + f(2) + f(1) +   3 =
f(2) + f(1) +   3  +   3  +   1  +   3  +   1  +   3 =
3  +   1  +   3  +   3  +   1  +   3  +   1  +   3 =```
i didnot get it

5. Sigh... after I put all that effort into aligning my post.

Do you at least understand the following?

1. f(6) = f(5) + f(4)
2. f(5) = f(4) + f(3)
3. f(4) = f(3) + f(2)
4. f(3) = f(2) + f(1)
5. f(2) = 3
6. f(1) = 1

If you can understand all of those, then it is simply a matter of substitution. If you can't...

6. Code:
```1. f(6) = f(5) + f(4)
2. f(5) = f(4) + f(3)
3. f(4) = f(3) + f(2)
4. f(3) = f(2) + f(1)
5. f(2) = 3
6. f(1) = 1```
i got it
thanks