Program Output Check
Program Output Check
Ans:
M=12
N=9
X=13
Y=8
Explanation:
At line 3 x = 10 , y = 10
At line 4 x = 11 , y = 9
main( ){
printf (“%d%d\n”, 32768, 32777);
printf (“%d\n”, ‘T’);
printf (“%c\n”, 97);
}
3276832777
84
a
#include<stdio.h>
main (void) {
int a = 20, b = 10, c, d;
c = ++a - b;
d = b++ +a;
Ans:
a = 21 b = 11 c = 11 d = 31
10
11
1.000000
#include<stdio.h>
main( ) {
int x = 0, y = 5, i = 2;
while (i--) {
x += 1; y -= 1;
printf("X= %d \n Y= %d", x, y);
}
}
Ans:
X= 1
Y= 4 X= 2
Y= 3
main( ){
int i=0, x=0;
do{
if ( i%5==0 ){
x++;
printf (“%d”, x);
}
++i;
} while (i<20);
}
Ans:
1234
Explanation:
Here, i=0 x=1
i=1
i=2
i=3
i=4
i=5 x=2
i=6
i=7
i=8
i=9
i=10 x=3
i=11
i=12
i=13
i=14
i=15 x=4
i=16
i=17
i=18
i=19
#include<stdio.h>
main() {
int n, m, p;
Ans:
n m p
1 50 50
2 49 24
3 48 16
4 47 11
5 46 9
6 45 7
7 44 6
8 43 5
9 42 4
10 41 4
11 40 3
12 39 3
13 38 2
14 37 2
15 36 2
16 35 2
17 34 2
18 33 1
19 32 1
20 31 1
21 30 1
22 29 1
23 28 1
24 27 1
25 26 1
#include<stdio.h>
main( ) {
int i, sum = 0;
1
3
6
10
15
21
28
36
45
55
66
78
91
105
y = 1;
if(x>=0)
if(x>0)
y = x + 1;
else
y = x - 1;
Ans:
#include<stdio.h>
main( ) {
int a, b, c, d;
a = 20; b = 15;
c = ++a - b;
printf (" a = %d b = %d and c = %d\n", a, b, c);
d = b++ +a;
printf ("a = %d b = %d and d = %d\n", a, b, d);
Ans:
a = 21 b = 15 and c = 6
a = 21 b = 16 and d = 36
a/b=1
a%b=5
a*= b = 336
0
1
#include<stdio.h>
main( ) {
char choice = 'W';
switch(choice)
{
case 'R':
printf("RED");
case 'W':
printf("WHITE");
case 'B':
printf("BLUE");
}
}
Ans:
WHITEBLUE.
When the switch statement is executed, it found the value of the expression is ‘W’. Then the
value compared against the values ‘R’, ‘W, ‘B’. Here a case is found (case ‘W’: ) whose value
matches with value of the expression ( ‘W’ ) so the control is transferred directly to that case.
Next the block of statements that follows the ( case ‘W’: ) are executed.
As no break statements is found at the end of that block which signals the end of a particular case
block and causes an exit from the switch statement, the subsequent case ( case ‘B’: ) is also
executed.
#include<stdio.h>
main( ) {
int a, b, x=0;
for (a=0; a<5; ++a)
for (b=0; b<a; ++b)
{
x += (a+b-1);
printf ("%d ", x);
}
printf ("\n x=%d", x);
}
Ans:
Here the output is:
0 1 3 5 8 12 15 19 24 30
x=30