Download presentation
Presentation is loading. Please wait.
Published byTracy Williamson Modified over 9 years ago
1
Introduction to Programming Lecture 5
2
In the Previous Lecture Basic structure of C program Basic structure of C program Variables and Data types Variables and Data types Operators Operators ‘cout’ and ‘cin’ for output and input ‘cout’ and ‘cin’ for output and input Braces Braces
3
Decision
4
If Statement If condition is true statements If Ali’s height is greater then 6 feet Then Ali can become a member of the Basket Ball team
5
If Statement in C If (condition) statement ;
6
If Statement in C If ( condition ) { statement1 ; statement2 ; :}
7
If statement in C if (age1 > age2) cout<<“Student 1 is older than student 2” ;
8
Relational Operators < less than <= less than or equal to == equal to >= greater than or equal to > greater than != not equal to
9
Relational Operators a != b; X = 0; X == 0;
10
Example #include #include main ( ) { int AmirAge, AmaraAge; AmirAge = 0; AmaraAge = 0; cout<<“Please enter Amir’s age”; cin >> AmirAge; cout<<“Please enter Amara’s age”; cin >> AmaraAge; if AmirAge > AmaraAge) { cout << “\n”<< “Amir’s age is greater then Amara’s age” ; }}
11
Flow Chart Symbols Start or stop Process Continuation mark Decision Flow line
12
Flow Chart for if statement Condition Process IF Then Entry point for IF block Exit point for IF block Note indentation from left to right
13
Example If the student age is greater than 18 or his height is greater than five feet then put him on the foot balll team Else Put him on the chess team
14
Logical Operators AND&& OR||
15
Logical Operators If a is greater than b AND c is greater than d In C if(a > b && c> d) if(age > 18 || height > 5)
16
if-else if (condition) { statement ; --}else{ --}
17
if-else Condition Process 1 IF Then Entry point for IF-Else block Exit point for IF block Process 2 Else Note indentation from left to right
18
Code if (AmirAge > AmaraAge) { cout<< “Amir is older than Amara” ; } if (AmirAge < AmaraAge) { cout<< “Amir is younger than Amara” ; } Example
19
Example Code if AmirAge > AmaraAge) { cout<< “Amir is older than Amara” ; cout<< “Amir is older than Amara” ;}else{ cout<<“Amir is younger than Amara” ; cout<<“Amir is younger than Amara” ;}
20
Make a small flow chart of this program and see the one to one correspondence of the chart and the code
21
Example Code if AmirAge > AmaraAge) { cout<< “Amir is older than Amara” ; cout<< “Amir is older than Amara” ;}else{ cout<<“Amir is younger than or of the same age as Amara” ; cout<<“Amir is younger than or of the same age as Amara” ;}
22
Example If (AmirAge != AmaraAge) cout << “Amir and Amara’s Ages are not equal”; cout << “Amir and Amara’s Ages are not equal”;
23
Unary Not operator ! !true = false !false = true
24
If (!(AmirAge > AmaraAge)) ?
25
Example if ((interMarks > 45) && (testMarks >= passMarks)) { cout << “ Welcome to Virtual University”; }
26
Example If(!((interMarks > 45) && (testMarks >= passMarks))) ?
27
Nested if If (age > 18) { If(height > 5) {:}} Make a flowchart of this nested if structure…
28
In Today’s Lecture Decision Decision – If – Else Flowcharts Flowcharts Nested if Nested if
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.