3
3
Enrolment No:
int main()
{
2 CO2
float x = 'a';
printf("%.0f", x);
return 0;
}
Q A3 Draw a flow chart to get a number from user and determine given number is odd or
2 CO1
even?
Q A4 Predict the output of the following C code:
int main() {
int num = 6;
int result = num << 2;
int result1=num>>2; 2 CO2
printf("After left shift by 2 bits:result= %d\n", result);
printf("After left shift by 2 bits: result1=%d\n", result1);
return 0;
}
Q A5 What is a pointer in the context of C programming? Provide a concise definition. Also
write the size of a character pointer and size of an integer pointer on a 32-bit system.
2 CO4
Page 1 of 4
SECTION B
Q B1 Write a C program that performs the following tasks sequentially.
#include <stdio.h>
int main()
{
/*
• Declare a variable named ‘temperature’ of type ‘double’.
• Read the value of ‘temperature’ from user.
• Prints one the following messages based upon the value of ‘temperature’ 6 CO3
(i) Prints “Freezing Weather” if ‘temperature is less than 0
(ii) Prints “Very Cold Weather” if 0 <= temperature <10
(iii) Prints “Cold Weather” if 10 <= temperature <20
(iv) prints “Normal Weather” if temperature >= 20
*/
}// End of Main
Page 3 of 4
SECTION-D
Q D1 Consider a scenario where you are tasked with developing a program in C to manage
a library's book inventory. The program should utilize structures to handle book
information. The program should perform the following tasks:
a. Define a structure named Book with the following attributes:
Book _ID (integer) 10 CO5
Title (string)
Price (float)
b. Create a structure to store information of 2 books in the library.
c. Display the information of both Books.
Q D2 Debug and complete the following C program, which intends to calculate the factorial
of a given number using a while loop.
#include <stdio.h>
int main() {
int number, factorial;
// Missing logic: Complete the code to ask the user for input and store it in
'number'
// Debug and fix the issues in the while loop
while (i <= number) {
factorial *= i;
}
// Missing logic: Complete the code to display the factorial
return 0; 10 CO3
}
a. Identify and correct the error in the while loop that leads to incorrect factorial
calculation.
b. Debug any logical errors preventing the correct determination of the factorial
within the while loop.
c. Explain why the original while loop was incorrect and how your correction
addresses the issue.
d. Suggest an alternative loop construct that could be used instead of the while
loop to achieve the same result.
e. Complete the missing logic in the code to ask the user for input and store it in
the variable 'number', and display the calculated factorial at the end.
Page 4 of 4