You are on page 1of 6

Programming Fundamentals

Lab Manual (Lab 4)

Topic: Simple if–else Statements

Lab Instructor: Ahmad Abduhu

Session: Fall 2018

School of Systems and Technology


UMT Lahore Pakistan
Objective

The aims of this lab are to cover some other basics of C programming Decision Control Structures in
detail.

 Comparison/Relational Operators
 Logical Operators
 If Statement
 If - else statement

Comparison/Relational Operators

Operator name Syntax

Less than or equal to a <= b

Less than or equal to a <= b

Greater than a>b

Greater than or equal to a >= b

Not equal to a != b

Equal to a == b

Logical Operators

Operator name Syntax

Logical negation (NOT) !a

Logical AND a && b

Logical OR a || b
Lab Tasks

Task 1:

Write a program which takes two numbers from the keyboard, and determine and display which
(if either) is the larger of the two numbers.

Sample Output

Program to find Larger number


*****************************
Enter first number: 25
Enter second number: 35
35 is larger

Task 2:

Write a program which takes year as an input through the keyboard then it determines whether the
year is a leap year or not.

Hint:(The year is evenly divisible by 4 and 400 but not divisible by 100 is said to be leap year.
Use the % (modulus) operator).

Sample Output

Program to find Leap year


**********************
Enter the year: 2002
The year is not a leap year

Task 3:

Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered
through the keyboard.
Hint: A triangle is valid if the sum of all the three angles is = 180
Sample Output

Program to find triangle


**********************
Enter the first angle: 90
Enter the second angle: 50
Enter the third angle: 40

This is Valid Triangle

Task 4:

Write a program which takes input from the keyboard and determine whether it is an even or odd number.
Program to find even number
**********************
Enter the Number: 90

This is a even Number


Bonus Tasks
Bonus Task 1:

The date June 10, 1960, is special because when we write it in the following format, the month times the
day equals the year.
6/10/60
Write a program that asks the user to enter a month (in numeric form), a day, and a two-digit year. The
program should then determine whether the month times the day is equal to the year. If so, it should display
a message saying the date is magic. Otherwise, it should display a message saying the date is not magic.

Sample Output(Case 1)

Is this Magic Date


**********************
Enter the day: 20
Enter the month: 11
Enter the third angle: 18

The date 20/11/18 is not a magic date.

Sample Output(Case 2)

Is this Magic Date


**********************
Enter the day: 6
Enter the month: 3
Enter the third angle: 18

The date 06/03/18 is a magic date.

Bonus Task 2:

The area of a rectangle is the rectangle’s length times its width. Write a program that asks for the length
and width of two rectangles. The program should tell the user which rectangle has the greater area, or if the
areas are the same.
Sample Output(Case 2)

Enter the length of 1st Rectangle: 7


Enter th width of 1st Rectangle: 4

Enter the length of 2nd Rectangle: 6


Enter th width of 2nd Rectangle: 5

The 2nd Rectangle has the greater area.

You might also like