DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
Roll No…………….. Total No. of Pages:……
ST-I (SET-4)
1st SEMESTER 2022-23
22CS002- FUNDAMENTALS OF C PROGRAMMING
Time allowed: 90 Minutes Max. Marks: 40
General Instructions:
● Follow the instructions given in each section.
● Make sure that you attempt the questions in order.
SECTION-A (10*1 mark=10 marks)
1. What is the purpose of a variable in C programming?
A. To store a value or data
B. To execute a function
C. To print output to the screen
D. To create a new data type
2. Which function is used to print output in C?
A. Printf();
B. printf();
C. scanf()
D. Scanf();
3. Which of the following arithmetic operators is used to increment a variable in C?
A. –
B. ++
C. +
D. None of the Above
4. Which of the following operator gives remainder?
A. *
B. /
C. %
D. ~
5. What is the format specifier used to read a string in C?
A. %c
_______________________________________________________________________CS114 - 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
B. %S
C. %s
D. %C
6. Which of the following is used to test the equality of two variables
A. ==
B. =
C. +=
D. -=
7. Which of the following symbol is used for the logical AND operator in C?
A. &
B. &&
C. !!
D. ||
8. The associativity of the assignment operator (=) in C is ----------------------?
A. Left to Right
B. Right to left
C. Either way is possible
D. None of them
9. What is the result of the following expression in C: 1+2*3
A. 5
B. 7
C. 9
D. 1
10. What is the syntax of an if statement in C?
A. if (condition) statement;
B. if {condition} statement;
C. if condition statement;
D. if (condition); statement;
SECTION-B (5*2 mark=10 marks)
(All questions are compulsory)
_______________________________________________________________________CS114 - 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
11. Which of the following operators has an associativity from Right to Left?
a) <=
b) <<
c) ==
d)+=
12. Which of the following is a valid expression in C?
a. int basic_pay=23000;
b. int basic_pay=23,000;
c. int basicpay==23000;
d. int$ basic_pay=23000;
[Link] of the following is not an arithmetic operation?
a.a*=5;
b.a/=5;
c. a!=5;
d.a%=5
[Link] will be the output for the following C code?
#include <stdio.h>
int main()
int x = 5, y = 2;
x *= x - y;
printf(“%d”, x);
return 0 ;
a)23
b) 15
c) Undefinedbehavior
d) 21
_______________________________________________________________________CS114 - 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
[Link] is the use of sizeof() operator
a. To get the size of data types or variables in bytes
b. To get the size of variables only
c. To get the size of the structure only
d. None of the above
SECTION-C(Coding Question) (2x5 marks=5 marks)
Question 16)
Problem Statement: A student will not be allowed to sit in the exam if his/her attendance is less than 75%. The student will be
only allowed to sit if he/she has a medical cause. Ask the user if he/she has a medical cause (Y or N). Take the following input
from the user:
a. No. of classes held
b. No. of classes attended
c. Has medical cause or not
Print % of classes attended and if the student is allowed to sit in the exam or not. Print accordingly.
Sample Input 1
150
100
Y
Sample Output 1
You have attended 66.67% classes. You are allowed to sit for the exam
Sample Input 2
150
100
N
Sample Output 2
You have attended 66.67% classes. You are not allowed to sit for the exam
Input Explanation
Input consists of two integer value and one character value
First input consists number of classes held
Second input consists number lecture attended
Third input consists only one character as Y or N in any case (upper/lower)
Output Explanation
_______________________________________________________________________CS114 - 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
Output will be in text formatted with number of percentage student addended the class and student is allowed to sit for exam or not.
Test Case 1 Test Case 2 Test Case 3 Test Case 4
150 50 100 200
Input
120 45 40 70
N Y N n
You have attended 80.00% You have attended 90.00% You have attended 40.00% You have attended 35.00%
Output
classes. You are allowed to sit classes. You are allowed to sit classes. You are not classes. You are not
for the exam for the exam allowed to sit for the exam allowed to sit for the exam
Solution:
#include <stdio.h>
int main()
int classes_held, classes_attended; char medical_cause;
float percentage;
scanf("%d", &classes_held);
scanf("%d", &classes_attended);
scanf(" %c", &medical_cause);
percentage = (float) classes_attended / classes_held * 100;
if (percentage < 75)
if (medical_cause == 'Y' || medical_cause == 'y')
printf("You have attended %.2f%% classes. You are allowed to sit for the exam\n", percentage);
else
_______________________________________________________________________CS114 - 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
printf("You have attended %.2f%% classes. You are not allowed to sit for the exam\n", percentage);
else
printf("You have attended %.2f%% classes. You are allowed to sit for the exam\n", percentage);
return 0;
Question 17: Leap year or Not
Checkwhetherayearisa leap yearornot if leap year output should be 1 else output should be 0.
Sample Input 1
2019
Sample Output 1
0
Sample Input 2
2400
Sample Output 2
1
Input Explanation
Input consists of one integer value as year
Output Explanation
Output consists of one digit integer value, 1 as leap, 0 as not leap year
Test Case 1 Test Case 2 Test Case 3 Test Case 4
Input
2000 1900 2008 2100
_______________________________________________________________________CS114 - 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
Output
1 0 1 0
Solution:
#include <stdio.h>
int main()
int year; int leap;
scanf("%d", &year);
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
leap = 1;
else
leap = 0;
printf("%d",leap);
return 0;
SECTION-D (Coding Question)(1x10 mark=10 mark)
Question 18: Allowed to take examination
_______________________________________________________________________CS114 - 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
A university is conducting St1 of students. The university decided to allow students having attendance more than 75%. A valid medical certificate can be considered. Help
the faculty to automate the examination system.
Input Explanation:
Input line 1: Medical certificate available enter in Y/N.
Input line 2: Total number of classes held
Input line 3: No of classes attended by the student
Output explanation:
Display of the student is allowed or not.
Sample Input:
120
90
Sample Output:
Allowed
Test Cases
Test Case 1 Test Case 2 Test Case 3 Test Case 4
Input n N Y y
120 100 100 160
90 50 90 100
Output Allowed Not allowed Allowed Allowed
_______________________________________________________________________CS114 - 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
Solution:
#include <stdio.h>
int main()
int classes_held, classes_attended;
char medical_cause;
float percentage;
scanf(" %c", &medical_cause);
scanf("%d", &classes_held);
scanf("%d", &classes_attended);
percentage = (float) classes_attended / classes_held * 100;
if (percentage < 75)
if (medical_cause == 'Y' || medical_cause == 'y')
printf("Allowed");
_______________________________________________________________________CS114 - 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
else
printf("Not allowed");
else
printf("Allowed");
_______________________________________________________________________CS114 - 2022-23