You are on page 1of 4

CT-1

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)

#include <stdio.h> Output:


int main()
{
int marks = 70;
if(marks > 100)
printf("Invalid");
if(marks >= 80)
printf("A+");
if(marks >= 70)
printf("A");
if(marks >= 60)
printf("B");
if(marks >= 50)
printf("C");
if(marks >= 40)
printf("D");
else
printf("F");
return 0;
}

4. Write a C program to take an integer number n (1<=n<=100) as input and (6)


print the following pattern. I have given an example for n=1, n=2, n=3, n=4,
and n=5. Your program should work for any value of n and should print the
similar pattern.

n=1 n=2 n=3 n=4 n=5

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)

#include <stdio.h> Output:


int main()
{
char c = 'e';
switch(c) {
case 'a':
printf("Vowel");
case 'e':
printf("Vowel");
case 'i':
printf("Vowel");
case 'o':
printf("Vowel");
case 'u':
printf("Vowel");
break;
default:
printf("Consonant");
}
return 0;
}

4. Write a C program to take an integer number n (1<=n<=100) as input and (6)


print the following pattern. I have given an example for n=1, n=2, n=3, n=4,
and n=5. Your program should work for any value of n and should print the
similar pattern.

n=1 n=2 n=3 n=4 n=5

0 0 0 0 0
01 01 01 01
010 010 010
0101 0101
01010

You might also like