Sie sind auf Seite 1von 21

Programming Language

Department of computer Science

University of Engineering and Technology


Week02 Lecture 03
Review Lectures

https://www.youtube.com/c/KamyabLife
Practice Question:06
Take three number as input and print the largest number as
output with message. Assumption None of these Numbers
are same
Problem Solution
We check 1st number is greater than 2nd number, if it is,
we need to check is it greater than 3rd number and if it is
print 1st number is greater.
Same thing we repeat for 2nd Number
Same things we repeat for 3rd Number
Start
Flow Chart
we check 1st number is greater than Input a, b, c
2nd number, if it is, we need to check
is it greater than 3rd number and if it
is print 1st number is greater. a>b

True

a>c
True

Print a is greater

End
Start

Input a, b, c

a>b

True

a>c
True

Print a is greater

End
Problem
Now, we need to add code that
check is b greater than a and
greater than c.
Problem
Now, we need to add code that
check is c greater than b
and greater than a.

This is a solution with


nested if
IF statement
We can combine multiple conditions in one IF statement instead of
having nested IF statements.
We can do it with help of logical operators.

logical operator
Logical AND (&&) Operator
Logical OR (II) Operator
Logical NOT(!) Operator
Logical Operators
Logical operators
Practice Problem 01: Valid Number
Write a program that take input number and
if it is between 40 and 50 (including both 40
and 50) Print Valid Number Otherwise print
Invalid Number.
Practice Problem:02
Write a Program that print valid number if number is
between 40 and 50 or it is between 60 and 80.
Practice Problem 03: My Grade
A school has following rules for grading system:
oBelow 25 - F
o26 to 45 - E
o46 to 50 - D
o51 to 60 - C
o61 to 80 - B
oAbove 80 - A
Ask user to enter marks and print the corresponding
grade.
Practice Problem:03
Practice
If x = 2, y = 5, z = 0 then find values of the following
expressions:
 x == 2
 x != 5
 x != 5 && y >= 5
 z != 0 || x == 2
 !(y < 10)
Thank You

Das könnte Ihnen auch gefallen