Everest Engineering College
Sanepa-2, Lalitpur
Subject: Programming in C Date of Distribution: . . . . . . . . . . . . . . . .
Date of submission: . . . . . . . . . . . . . . . . .
Lab 2
Title: Decision control statements
Objective:
• To be familiar with decision control statements
• To be familiar with different operators in C
Theory:
➢ Decision control statements (If, if-else, nested -if else, else-if ladder)
➢ Operators and operand (Arithmetic operator, Relational operator, Logical operator)
Lab Exercises:( Please code yourself and show the output to the instructor)
1) Write a program to check the given number is odd or even.
2) Write a program to find maximum among two numbers.
3) Write a program to check the given number is exactly divisible by 5 but not 7.
4) Write a program to check the given year is leap year or not.
5) Write a program to read a positive integer value and compute the following sequence. If
the number is even half it, if it is odd multiply it by 3 and add 1 and print the result. If
input value is less than 1 print the message containing the word “ERROR”.
6) Write a program to calculate the real roots of the quadratic equation ax2 + bx + c = 0. If
the roots are imaginary display the message “Error”.
7) Write a program to read three sides of triangle and print area for valid data and to print
“Invalid data” if either one side of the triangle is greater or equals to the sum of other two
sides.
8) Write a program to find largest among three numbers. (use nested-if else)
9) Write a program to find largest among four numbers.
10) Write a program to read a temperature of a day in Fahrenheit and print
“Nice day” if temperature is greater than 60 but less than 80.
“Cold day” if temperature is 60 or lower.
“Hot day” if temperature is 80 or higher.
Prepared By: Er. Pradip Paudel 1|Page
11) An electricity board charges according to following rates.
For the first 20 units …………………….Rs.80
For the next 80 units……………….Rs.7.5 per unit
For the next 100 units ……………….Rs. 8.5 per unit
For the beyond 200 units…….. . ..Rs.9.5 per unit And Tax 15% in total amount is
charged to all users. Write a program to read number of units consumed and print out the
total charge.
12) Write a program to read to read length and breadth of a room and print area and print.
“Auditorium” if area >2500
“Hall” if 500 < = area <=2500
“Big room” if 150 < area < 500
“Small room” if area < = 150
13) Let's consider the supermarket discount policy: the policy offers a 5% discount on the total
bill to all customers, irrespective of their purchase amount. Additionally, female customers
receive an 10% discount if their total bill exceeds Rs. 5000. Write a C program to
implement this discount policy and calculate the final bill after applying these discounts.
14) Write a program to find out the grade of student. When the marks of four subjects are
given. The method of assigning grade as:
Percentage Grade
More than or equals to 85 A
Less than 85 or more than or equals to 70 B
Less than 70 or more than equals to 55 C
Less than 55 or more than or equals to 45 D
Less than 45 or more than or equals to 32 E
Less than 32 F
Prepared By: Er. Pradip Paudel 2|Page