Programming for Problem Solving using C UNIT TEST - I
[Link]. Question Description Marks
1 A Identify and list any 3 keywords in C and explain their usage with a short code 2
snippet.
B Write a statement in C declaring an integer variable and assign a value to it. State 2
the datatype used.
C What will be the output of this statement? 1
printf(“%d”, 8 + 3 * 2 );
Explain briefly the evaluation.
(Note: No syntax error in the line given)
2 a Write a C program fragment to take user input for two numbers and print 2
their sum using scanf() and printf().
b Identify the error in the following statement and correct it: 1
scanf("%d", number);
c Write a C code to read a character, integer, double values from user input 2
and display it.
3 a Write a C program that checks if a number entered by the user is positive, 2
negative or zero using if-else statements.
b Write code in C to print the greatest of three given numbers using 2
conditional statements. (Hint: use logical operators)
c Write a C code to check and print whether a given number is even or odd 1
using. (Hint: Ternary or conditional operator)
4 a Switch-case is also a multi-way decision making statement. Based on the 3
above, Inspect the functionality of it with an example.
b You are given a number, asking you to generate the multiplication table 2
for it. Assume, you’ve given a freedom to use any of the loop statement.
Write a code to depict the above.
Sample output:
Enter a number: 5
5*1=5
5 * 2 = 10
:
:
5 * 10 = 50
5 a Explain about logical operators (&&, ||, !) operators with a suitable 2
example for each.
b {Use Logical OR / Switch case}: check for the given character is a vowel 3
or not [3]
6 A Explain about Exit controlled loop (Do-While) statement with its syntax, 2
flow- chart and example program.
B Program to print the sum of first n natural numbers. Where ‘n’ should be 3
read from the keyboard.
7 A Program to check whether the given letter is an alphabet, or a digit, or a 3
special character. (Hint: Use else-if statement)
B Draw the flow-chart and syntax of “else-if” ladder. 2
8 A Explain about pre-test loop (for loop / counter controlled loop) 2
statement with its syntax, flow-chart and example program.
B Program to find the factorial of a given number 3
9 A Explain about increment/decrement operators (++/--) with a suitable 3
example for each.
B List out primitive data types and their specifications (size, control strings 2
and keyword) supported by c language
10 A Identify and correct the logical error in the following loop: 2
int i = 5;
while(i > 0) {
printf("%d", i);
}
Rewrite the code after correcting the logical error.
B Analyze the output of this loop and explain: (assume, no syntax errors in 2
the code)
for(int i=1; i<=15; i++) { [2]
if(i%2==0) printf("%d ", i);
}
C Given the code below, explain what it does and suggest an improvement 1
to print numbers in reverse order (assume, no syntax errors in the
code)
for(i=1; i<=5; i++){ [1]
printf("%d ",i);
}
Rewrite the code