Taylor Jane - 8 months ago 57

C Question

I know the answers are a=0, b=10, and c=2 because I wrote it out and compiled it, but I'm unsure of how the answers were found.

`#include <stdio.h>`

int f(int a, int b)

{

int c;

c=3*a-b;

a=(c+17)%23;

b=23%(a+5);

return a-b+c;

}

int main()

{

int a=7, b=3, c=2;

a=f(c,b);

b=f(a,c);

printf("a=%d,b=%d,c=%d\n", a,b,c);

return 0;

}

Answer

Let's do this line by line -

a = f(c,b) -

```
c = 3 * a - b --> (3 * 2) - 3 = 3
a = (c+17) % 23 --> 20 % 23 = 20
b = 23 % (a+5) --> 23 % 25 = 23
return a - b + c --> 20 - 23 + 3 = 0
```

a = 0

b=f(a,c) -

```
c = 3 * a - b --> (3 * 0) - 2 = -2
a = (c+17) % 23 --> (-2 + 17) % 23 = 15
b = 23 % (a+5) --> 23 % 20 = 3
return a - b + c --> 15 - 3 + -2 = 10
```

b = 10

And c value remain 2