...
Operating-Systems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023
Operating-Systems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023

Programming-for-Output-Problems

Question 2

Consider the following C program:

         #include <stdio.h>
         int jumble (int x, int y)  {
               x = 2 * x + y ;
               return x ;
         }
         int main ( )  {
               int x=2, y=5 ;
               y = jumble (y, x) ;
               x = jumble (y, x) ;
               printf ("%d \n", x) ;
               return 0 ;
         }

The value printed by the program is ______.

A
26
B
67
C
25
D
13
Question 2 Explanation: 
////////////////////////////////////Program
#include
int jumble(int x, int y)
{
printf(“Inside jumble : 2*%d + %d\n”, x,y);
x = 2*x +y;
return x;
}
int main()
{
int x=2, y=5;
printf(“Initial x=%d, y=%d\n”,x,y);
printf(“1st jumble call : jumble(%d,%d)\n”,y,x);
y = jumble(y,x);
printf(“Value of y after 1st jumble = %d\n”, y);
printf(“2nd jumble call: jumble(%d,%d)\n”, y,x);
x = jumble(y,x);
printf(“Value of x after 2nd jumble = %d\n”, x);
printf(“Final : %d\n”, x);
return 0;
}
////////////////////////////////////OUTPUT
Initial x=2, y=5
1st jumble call: jumble(5,2)
Inside jumble : 2*5 + 2
Value of y after 1st jumble = 12
2nd jumble call: jumble(12,2)
Inside jumble : 2*12 + 2
Value of x after 2nd jumble = 26
Final : 26
Correct Answer: A
Question 2 Explanation: 
////////////////////////////////////Program
#include
int jumble(int x, int y)
{
printf(“Inside jumble : 2*%d + %d\n”, x,y);
x = 2*x +y;
return x;
}
int main()
{
int x=2, y=5;
printf(“Initial x=%d, y=%d\n”,x,y);
printf(“1st jumble call : jumble(%d,%d)\n”,y,x);
y = jumble(y,x);
printf(“Value of y after 1st jumble = %d\n”, y);
printf(“2nd jumble call: jumble(%d,%d)\n”, y,x);
x = jumble(y,x);
printf(“Value of x after 2nd jumble = %d\n”, x);
printf(“Final : %d\n”, x);
return 0;
}
////////////////////////////////////OUTPUT
Initial x=2, y=5
1st jumble call: jumble(5,2)
Inside jumble : 2*5 + 2
Value of y after 1st jumble = 12
2nd jumble call: jumble(12,2)
Inside jumble : 2*12 + 2
Value of x after 2nd jumble = 26
Final : 26
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!