Process-Scheduling
October 6, 2023Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
Question 5 |
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 ______.
26 | |
67 | |
25 | |
13 |
Question 5 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
#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 5 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
#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
Subscribe
Login
0 Comments