Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

LAB # 5

NESTED if else STATEMENT AND LOGICAL

OPERATORS

1. OBJECTIVE:

1.1. The objective of C language is simple, designed to enable sophisticated objective-


oriented programming. Easy to analyze program. Help to understand the logic of
programming.
1.2. The objective of C language is simple, designed to enable sophisticated objective-
oriented programming. Easy to analyze program. Help to understand the logic of
programming.

NESTED if STATEMENT:

We write an entire if-else construct within either the body of the if statement or the body of
an else statement. This is called nesting of ifs.

LOGICAL OPERATORS:

C allows usage of three logical operators, namely,&&, || and !. These are to be read as
AND, OR and NOT respectively.

2. IN-LAB TASKS:

Task#1
Write a program to check whether the alphabet entered by user is vowel or consonant.

 CODE:

 OUTPUT:

Programming Fundamental Page 1


Task#2
Write a C program to input a character from user and check whether the given character is an
alphabet, number or a special character by using nested if else.

 CODE:

 OUTPUT:

Task#3
Write a program to enter month number and print number of days in the month by using
nested if else.

 CODE:

Programming Fundamental Page 2


 OUTPUT:

Task#4
Write a program to input sides of a triangle and check whether the triangle is equilateral, isosceles
and scalene by using nested if else.

 CODE:

 OUTPUT:

Programming Fundamental Page 3


Task#5

 Write a program to find whether the point lies in x-axis or y-

axis. CODE:

 OUTPUT:

Task#6

Write a program to enter the age of three student and check who is the youngest among them.

 CODE:

Programming Fundamental Page 4


 OUTPUT:

POST-LAB TASKS:

Task#1
A company insures its driver in the following cases: If

the driver is married.

If the driver is unmarried,male and above 30 years of age. If

the driver is unmarried,female and above 25 years of age.

Programming Fundamental Page 5


In the all other cases the driver is not insured. If the marital status,gender and age of the diver are
the inputs, write a program to determine whether the driver is insured or not.

 CODE:

 OUTPUT:

Programming Fundamental Page 6


 CODE:

 OUTPUT:

Task#2
Write a C program to input electricity unit charges and calcuate total electricity bill according
to the given coditions. For first 50 unitsRs. 0.50/unit. For next 100 units Rs. 1.50/unit. For next
100 units Rs. 0.75/unit. For unit above 250 Rs. 1.50/unit. An additional subcharge of 20% is
added to the bill.

 CODE:

Programming Fundamental Page 7


 OUTPUT:

Programming Fundamental Page 8

You might also like