Question

#include<stdio.h> int f(int a,int b); int main(){ int a=8, b=4,c=2; b = f(c,a); printf("a=%d,b=%d\n,a,b,c); c =...

#include<stdio.h>
int f(int a,int b);
int main(){
int a=8, b=4,c=2;
b = f(c,a);
printf("a=%d,b=%d\n,a,b,c);
c = f(a+3,b-2);
printf("a=%d,b=%d,c=%d\n",a,b,c);
return 0;
}
int f(int a, int b){
a=b+6
b=a-2
printf("a=%d,b=%d\n",a,b);
return a+b;
}
what is the first line of output produced?
what is the second line of output?
what is the third line if output?
what is the forth line of output?
if there is problems ill post the choices thank you
1 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

(a)

Explanation:

Finding first line of output:

=>We can see that main() function is called first in the program and inside main() function 3 variable a, b and c are declared as integer type and assigned values as below-

a = 8, b = 4 and c = 2

=>Now b = f(c, a) is called so value of c will be copied to variable a declared in the function f and value of a will be copied to variable b declared in the f so the values of variables inside function f are below-

a = 2, b = 8

=>Now a = b + 6 is executed means a = 8 + 6 => a = 14

=>Now b = a-2 will be executed means b = 14 - 2 => b = 12

=>now printf("a=%d,b=%d\n",a,b); will be executed and value of variable a and b will be printed and after printing the value line will be changes as \n is there.

=>Hence output is: a=14,b=12

(b)

Explanation:

Finding second line of output:

=>Value a + b will be returned to the main() function from function f.

=>a + b = 14 + 12

=>a + b = 26

=>So b = f(c, a); will now be completed and b = 26

=>Now printf("a=%d,b=%d,c=%d\n",a,b,c); will be executed and values of variables a, b and c will be taken from main() function and then line will be changes using \n.

=>Hence output is: a=8,b=26,c=2

(c)

Explanation:

Finding third line output:

=>Now c = f(a + 3, b-2) will be called means c = f(8 + 3, 26 - 2)

=>c = f(11, 24) will be called

=>Values of variables inside function f will have values as below

a = 11, b = 24

=>a = b + 6 means a = 24 + 6 => a = 30

=>b = a - 2 means b = 30 - 2 => b = 28

=>Hence third line output is: a=30,b=28

(d)

Explanation:

>a + b = 30 + 28

=>a + b = 58

=>c = f(11, 24) is completed now.

=>c = 58

=>So final value in main() function: a = 8, b = 26 and c = 58

=>Fourth line output is: a=8,b=26,c=58

I have explained each and every part with the help of statements attached to it.

Add a comment
Know the answer?
Add Answer to:
#include<stdio.h> int f(int a,int b); int main(){ int a=8, b=4,c=2; b = f(c,a); printf("a=%d,b=%d\n,a,b,c); c =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Having an issue with pointers and functions. #include <stdio.h> int f(int *a, int *b); int main()...

    Having an issue with pointers and functions. #include <stdio.h> int f(int *a, int *b); int main() { int a = 2, b = 7; b = f(&b, &a); printf("a = %d,\n", a); printf("b = %d\n", b); return 0; } int f(int* a, int* b) {     (*a) = (*a) + 3;     (*b) = 2*(*a) - (*b)+5;     printf("a = %d b = %d\n", *a, *b);     return(*a)+(*b); } can someone explain to me why the output is a =...

  • 1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf...

    1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf ("Hello!") return 0 2 Assume a program has the following declarations: short s- 4 int i--5; long m-3 float f-19.3f; double d-3.6; What are the following values? (a) s+m (b) (float) d (c) d s (e) (int) f 3 What will be the output of the following program: int x = 3 float a 2.76; y-2* x; print f("X-2d, y*ta, z»%d", x, y, z);...

  • what is output #include<stdio.h> pint main() { int i, j, total; for ( 2 { printf("\n");...

    what is output #include<stdio.h> pint main() { int i, j, total; for ( 2 { printf("\n"); for ( 2 { total = i + j; printf("%d", total); بہا } getchar(); return 0; } Find the for loop content | Output of progrm 5 15 1 11 21 31 41 51 61 2 12 22 32 25 3 13 23 33 43 53 63 4 14 24 34 44 54 64 35 45 6 16 26 36 46 56 66 7...

  • i need flowchart for the following c code #include <stdio.h> int main() {     int n,...

    i need flowchart for the following c code #include <stdio.h> int main() {     int n, i, sum = 0;     printf("Enter an integer: ");     scanf("%d",&n);     i = 1;     while ( i <=n )     {         sum += i;         ++i;     }     printf("Sum = %d",sum);     return 0; }

  • What is the output of the following code? #include« stdio.h» 2 4 int main() 6 int...

    What is the output of the following code? #include« stdio.h» 2 4 int main() 6 int a=15,b=12,c=5, d-e; 7 printf("the value of d is %d",d); return 0; 8 9 10 Ly 0 29 O 30 0 28 O 31

  • All in C please~ #1 Consider this program: #include <stdio.h> int main () { /* main...

    All in C please~ #1 Consider this program: #include <stdio.h> int main () { /* main */ constint constant1 = 10, constant2 = 20, constant3 = 14; int input_value; char current_truth; printf("What is the input value?\n"); scanf("%d", &input_value); current_truth = input_value > constant1; printf("current_truth = %d\n", current_truth); current_truth = current_truth && (input_value < constant2); printf("current_truth = %d\n", current_truth); current_truth = current_truth && (input_value == constant3); printf("current_truth = %d\n", current_truth); } /* main */ What is the output of this program...

  • #include <stdio.h> #include <stdlib.h> int aaa(); int main() { int ddd,eee = aaa (ddd,eee); printf("new num...

    #include <stdio.h> #include <stdlib.h> int aaa(); int main() { int ddd,eee = aaa (ddd,eee); printf("new num 1 = %d, new num2 = %d.\n", ddd,eee); return 0; } int aaa(int bbb,int ccc) {    bbb = 111;    ccc = 222;    printf("num 1 = %d, num 2 = %d.\n", bbb,ccc);    return bbb ,ccc;   } Output: num 1 = 111, num 2 = 222. new num 1 = 0, new num2 = 222. ************************************************************** I am learning function in C....

  • #include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x)...

    #include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x) = x*x*x\n"); printf ("c: c(x) = x^2 + 2*x + 7\n"); printf ("q: quit\n"); } void a(float x) { float v = x*x; printf (" a(%.2f) = %.2f^2 = %.2f\n", x, x, v); } // end function a void b(float x) { float v = x*x*x; printf (" a(%.2f) = %.2f^3 = %.2f\n", x, x, v); } // end function b void c(float x)...

  • Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() {     int...

    Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() {     int number;     scanf("%d", &number);     if (number % 2 == 0) {         printf("Even\n");     }     else {         printf("Odd\n");     }     return 0; }

  • Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int...

    Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT