Professional Documents
Culture Documents
Set-1
1. Write a C program to take an integer number as input and calculate the sum (5)
of its odd digits. You can assume the given number will be between -108 to
108.
Sample Input Corresponding Output
12534 6
-209429 18
2. What does the following program do? Explain with justification if there is any (5)
non-positive input for which it gets stuck instead of showing the expected
output?
# include <stdio.h>
int main(){
int i, num;
scanf("%d", &num);
for (i=num; i-1; num*=--i);
printf("%d\n", num);
return 0;
}
3. See the following code and write down the output of this program. (4)
1 1 1 1 1
10 10 10 10
101 101 101
1010 1010
10101
CT-1
Set-2
1. Write a C program to take an integer number as input and calculate the (5)
product of its even digits. You can assume the given number will be between
-108 to 108.
Sample Input Corresponding Output
12534 8
-219429 16
2. What does the following program do? Write down the values of all the (5)
variables in each iteration of the loop (here, iteration means each time the
body of the loop is executed) for the input, a = 24, b = 9.
# include <stdio.h>
int main(){
int a, b, c;
scanf("%d %d", &a, &b);
for ( ;b; a=b,b=c) c = a%b;
printf("%d\n", a);
return 0;
}
3. See the following code and write down the output of this program. (4)
0 0 0 0 0
01 01 01 01
010 010 010
0101 0101
01010