Give the output on the screen of the following program
#include <stdio.h>
#define PRINT(format,x) printf(#x " = %"#format"\t",x)
#define NL putchar('\n');
#define PRINT1(f,x) PRINT(f,x);NL
#define PRINT2(f,x1,x2) PRINT(f,x1);PRINT1(f,x2)
#define PRINT3(f,x1,x2,x3) PRINT(f,x1);PRINT2(f,x2,x3)
#define PRINT4(f,x1,x2,x3,x4) PRINT(f,x1);PRINT3(f,x2,x3,x4)
int main()
{
int x , y, z;
x=y=0;
while(y<10) ++y; x+=y;
PRINT2(d,x,y);
x=y=0;
while(y<10) x+= ++y;
PRINT2(d,x,y);
y=1;
while(y<10){
x=y++;z=++y;
}
PRINT3(d,x,y,z);
for(y=1;y<10;y++) x=y;
PRINT2(d,x,y);
for(y=1;(x=y)<10;y++);
PRINT2(d,x,y);
for(x=0,y=1000;y>1;x++,y/=10)
PRINT2(d,x,y);
for(x=0,y=1000;y>1;x++,y/=10) {
PRINT2(d,x,y);}
return 0;
}
Difficulty level
This exercise is mostly suitable for students
x = 10 y = 10
x = 55 y = 10
x = 9 y = 11 z = 11
x = 9 y = 10
x = 10 y = 10
x = 0 x = 1 x = 2 y = 1
x = 0 y = 1000
x = 1 y = 100
x = 2 y = 10
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Nearest common ancestors in binary trees