Page |1
Practice Problems on Conditionals
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996 (Whatsapp)
Page |2
6. Write a C program to input temperature in degree Fahrenheit and convert it to
degree Centigrade.
7. Write a C program to input the number of days from the user and convert it to
years, weeks, and days. (Ignore leap years.)
8. Write a C program to print the next character of the input character.
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996 (Whatsapp)
Page |3
9. Write a C program to convert a character to uppercase.
10. Write a C program to convert a character to lowercase.
11. Write a C program to print the ASCII value of the input character.
12. Write a C program to print total number of days in a month both by using if-
else and by using switch case.
13. Write a C program to determine whether an input character is lower case or
upper case using switch case.
14. Write a C program to print the slope of the line, given two points on it.
Input: Take four integers for the values of x₁, y₁, x₂, y₂.
15. Write a C program to find the roots of a quadratic equation:
ax² + bx + c = 0
[Hint: The sqrt function can be used to find the square root of a number.]
Input: Take three floating-point numbers as input for the values of a, b, and c.
Output: The two roots rounded exactly to three decimal places.
16. Take three numbers as input: the three angles of a triangle and determine
whether the triangle is valid or not (angle value should be such that 0 < value <
180).
[Recall that a triangle is valid if the sum of all three angles is equal to 180
degrees.]
17. Take two integers: x and y as input and print "x is divisible by y" as output if
that holds. Otherwise, print "x is not divisible by y".
[Recall that you can use the % operator to get the remainder when one number is
divided by another. In particular, n%d evaluates to the remainder when n is
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996 (Whatsapp)
Page |4
divided by d. For example, 8%3 is 2 because if you divide 8 by 3, you get a
remainder of 2.]
18. Write a C program that takes as input two positive integers n and d and
outputs whether d is a proper divisor of n.
[Recall that a proper divisor of a positive integer n is a divisor of n that is not
equal to n. So, 1, 2, and 3 are proper divisors of 6 but 6 isn't.]
19. FIZZBUZZ
We will implement the game called FizzBuzz!
In this game, there are 4 rules:
1. If a number is divisible by 3, then print "fizz".
2. If a number is divisible by 5, then print "buzz".
3. If a number is divisible by both 3 and 5, then print "fizzbuzz".
4. If none of the above is applicable, just print the number.
You will input an integer and then produce an output according to these rules.
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996 (Whatsapp)
Page |5
Online Problems of CSE Lab on Conditionals:
Problem #1 (10 marks)
Electricity Bill
Write a C program to compute the electricity bill. You will be the number of units of electricity consumed
by a customer. The final bill will be calculated according to the following conditions:
● For first 50 units $ 2/unit
● For next 100 units $ 3/unit
● For next 100 units $ 4/unit
● For unit above 250 $ 6/unit
● An additional surcharge of 20% is added to the bill.
Write a C program to calculate electricity bill using if-else.
Sample Input(s) Corresponding Output(s)
10 24
100 300
1000 6360
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996 (Whatsapp)
Page |6
Problem #3 (10 marks)
Circle
In this problem, you will be given the x and y coordinates of the center of a circle and the radius of the
circle. You will be given the x and y coordinate of another point. Your program should determine whether
the point is inside, on or outside the circle.
The first three integers of each set of input indicates the x and y coordinates of the center and the radius of
the circle. The next two integer corresponds to the x and y coordinates of the point.
Sample Input(s) Corresponding Output(s)
0 0 10 1 1 Inside the circle
0 0 10 0 10 On the circle
0 0 10 0 11 Outside the circle
Problem #4 (10 marks)
Max
Given 4 integers write a program to find the maximum of the integers. You cannot use if-else or switch-
case.
Sample Input(s) Corresponding Output(s)
1234 4
4321 4
1542 5
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996 (Whatsapp)
Page |7
Problem #5 (10 marks)
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996 (Whatsapp)
Page |8
Problem #6 (10 marks)
Term Final Questions
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996 (Whatsapp)
Page |9
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996 (Whatsapp)
P a g e | 10
The Problems of this sheet are taken mainly from previous year Lab Assessments and
Term Final Questions of BUET.
C Programming Course
Instructor – Md. Abdullah (EEE-19,BUET), 01521706996 (Whatsapp)