Question

Could you please provide a detailed step by step explanation as to how I should go...

Could you please provide a detailed step by step explanation as to how I should go about obtaining the output shown for each program fragment.

Thanks.

a)

int f1 (int x) {

int y=3;

printf("%d%d",x,y);

return x++;

}

int main (void) {

int y=6, x=4;

printf("%d\n",f1(y));

printf("%d%d\n",x,y);

return 0;

}

OUTPUT:

x=6, y=36

x=4, y=6

b)

void f2(int n, int a[]) {

for (int i=0;i<n;i++)

a[i] += a[i+1];

}

int main() {

int A[]={1,2,3,3,4,5};int i, N=6;

for (i=0;i<N;i++)

printf("%d ",A[i]);

printf("\n");

f2(N-1,A);

for (i=0;i<N;i++)

printf("%d ",A[i]);

return 0;

}

OUTPUT:

A[i] = {1 2 3 3 4 5 }

A[i] = {3 5 6 7 9 5 }

c)

int f3 (int a, int b) {

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

if (b==1)

return a;

else

return a * f3(a,b-1);

}

int main (void) {

int y=6, x=2;

printf("%d\n",f3(x,y));

return 0;

}

OUTPUT:

a-b = 2-6

2-5

2-4

2-3

2-2

2-1

f3(x,y) = 64

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Could you please provide a detailed step by step explanation as to how I should go...
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
  • I NEED HELP WITH THE FLOWCHART AND PSEUDOCODES OF THIS PROGRAM PLEASE! +3) (5 pts) Show...

    I NEED HELP WITH THE FLOWCHART AND PSEUDOCODES OF THIS PROGRAM PLEASE! +3) (5 pts) Show the screen output of running the following program. #include <stdio.h> Screen output: int f1(int, int); //function declaration void f2(int); int main() { printf("calling f1( ) ..\n"); int flResult = f1(7,-8); printf("flResult = %d\n", f1Result); }//main) int f1(int a, int b) { printf("in f1(): a = %d, b = %d\n", a, b); int data = -1; if (a >b) data = a - b: return...

  • I know the right answers by using a compiler. However, can you please explain each step...

    I know the right answers by using a compiler. However, can you please explain each step and how you get the correct answer. Thank you in advance. Output: E = 1 F = 7 G = 11 H = 14 W = 5 X = 6 Problem 7 #include <iostream> #include <cmath> using namespace std; void F1(int,int,int,int&); void F2(int,int&,int&,int&); int main ( void ) { int E=1,F=2,G=3,H=4,W=5,X=6;    F1(E,F,G,H);    F2(E,F,G,H);    cout << "E = " << E <<...

  • Java 1. Can you explain it how it will be printed step by step? Thanks!! What...

    Java 1. Can you explain it how it will be printed step by step? Thanks!! What is printed by the following? for (int i=1; i<4; i++) { for (char c=’a’; c<=’c’; c++) { if (i%2==0) { i++; System.out.println(i + " " + c); } else { c++; System.out.println(c + " " + i); } } } 2. Is there a compiler error in this code? If so, what is it? If not, what’s printed? Is there a compiler error in...

  • Could you please do these questions using C and provide the codes and outputs for all...

    Could you please do these questions using C and provide the codes and outputs for all question? Thank you! ° Chapter 17-page 454 Exercise #5 has a question-code the problem and run it to determine the answer - Take a screenshot of the code and the answer Suppose that f and p are declared as follows: struct 5. union char a, b; int c int e (5] Which of the following statcments are legal? (b) p->e(310; (d) p->d->c20; o Chapter...

  • Three is 3 questions please answer them all Question 1 int main(void) { int x =...

    Three is 3 questions please answer them all Question 1 int main(void) { int x = 10, y = 20; if (x == y); printf ("\n%d %d",x,y); } Output as you would see on the compiler: Question 2 int main(void) { int x = 3, y = 5; if (x == 3) printf ("\n%d",x); else ; printf("%d", y); return 0; Output as you would see on the compiler: Question 3 int main(void) { int x = 3; float y =...

  • Whats wrong with my code? Please help! #include <stdio.h> int main() { //variables int m1, m2,...

    Whats wrong with my code? Please help! #include <stdio.h> int main() { //variables int m1, m2, m3; int a1, a2, a3; int f1, f2, f3; //input acceleration printf("Enter value for a1: "); printf("Enter value for a2: "); printf("Enter value for a3: "); scanf("%d %d %d",&a1,&a2,&a3); //input mass printf("Enter value for m1: "); printf("Enter value for m2: "); printf("Enter value for m3: "); scanf("%d %d %d",&m1,&m2,&m3); //functions f1=m1*a1; m1=f1/a1; a1=f1/m1; f2=m2*a2; m2=f2/a2; a2=f2/m2; f3=m3*a3; m3=f3/a3; a3=f3/m3; //command: printf("f1=%d\n, m1=%d\n, a1=%d\n"); printf("f2=%d\n,...

  • Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int);...

    Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int); int main() { f1(10); return 0; } void f1(int n) { f2(n + 5); } void f2(int n) { f3(n - 2); } void f3(int n) { cout << n << endl; // LINE 1 } Just before the program statement marked with the comment "LINE 1" is executed, how many stack frames will be on the program call stack?

  • 1-Is it possible to run a program without a main() function? Yes No 2- How many...

    1-Is it possible to run a program without a main() function? Yes No 2- How many main() functions can one have in a program? 2 This depends on what compiler you use. As many as you like 1 3- What does the following code fragment leave in x? char a = 'A'; int x = sizeof (a); 1 Depends on what compiler you use. 4 2 4- True or false: In a C program I can have two functions with...

  • 20) What is the output of the following segment of C code: int avg(int n, int*...

    20) What is the output of the following segment of C code: int avg(int n, int* a); int main () {             int array[4]={1,0,6,9};             printf("%d", avg(4, array)+ 1);             system("pause");             return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...

  • C programming problem please help my computer crashed what is the output of each program ?...

    C programming problem please help my computer crashed what is the output of each program ? (c) #include <stdio.h> int main() { /* main */ int f3, t = 9; int func3 (int x); printf("Inside main, t = $d\n", t); f3 - func3(t); printf("Inside main, f3 = %d\n", f3); return 0; } /* main */ int func3 (int x) { /* func3 */ printf("Inside func3, X = %d\n", x); return x; } /* func3 */ (d) #include <stdio.h> int main()...

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