Presentation2.pptx Computing
Presentation2.pptx Computing
Presented by:
M.SHAKEEL, MUBEEN SALEEM, M.IJAZ,WAJID
KHALIQ
Contents
Conditional Statements
If statement
If else statement
If else if statement
Nested if statement
Switch statement
What is conditional statement?
Conditional statement allow you to make a decision based
on the result of condition.
Types:-
➢ If statement
➢ If else statement
➢ If else if statement
➢ Nested if statement
➢ Switch statement
What is if statement ? Explain.
If statement is used when we test a condition, if condition is true then
if block statement will be executed, otherwise skipped remaining code
Syntax of if statement
if (condition)
{
statement;
// block of code to be executed if the condition is true
}
M.Shakeel
Flowchart of if statement
M.Shakeel
Example of If statement
Write a program that inputs two numbers and finds if second number is square of first.
#include<iostream.h>
#include<conio.h>
int main()
{
Output:
clrscr(); Enter a number: 5
int a,b; Enter a number: 25
cout<<“Enter a number”;
2nd number is square of 1st
cin>>a;
cout<<“Enter a number”;
cin>>b;
if (a*a==b)
{
cout<<“2nd number is square of 1st number”;
}
getch();
}
M.Shakeel
What is if else statement ? Explain.
Mubeen saleem
Example of If else statement
Write a program that inputs a number and finds whether is even or odd using if else.
#include<iostream.h>
#include<conio.h>
int main()
{ Output:
clrscr();
int n; Enter a number: 10
cout<<“Enter a number”; 10 is even.
cin>>n;
if (n%2==0)
{
cout<<n<< “is even”;
}
else{
cout<<n<<“is odd;
}
getch();
}
Mubeen saleem
What is if else if statement ? Explain.
It is used to perform multiple cases for different conditions.in this statement
there is one if condition and multiple else if conditions and one else block.
Syntax of if else if
M.Ijaz
flowchart of if else if statement
M.Ijaz
Example of If else if statement
Write a program that inputs test score of a student and display his grade
according to his following criteria:
M.Ijaz
Example of If else if statement
Output:
Enter your test score: 74
Your grade is C.
M.Ijaz
What is Nested if statement ? Explanation.
When we define if block inside another if block is called nested if
statement.
Syntax of if else if
Wajid khaliq
Example of Nested if statement
Write a program that inputs three numbers and display whether all
number are equal or not using nested if condition:
Output:
Enter three numbers: 74 ,25 30
Numbers are different
Wajid khaliq
What is Switch statement ? Explain.
The Switch statement is another conditional structure.it can be used easily
when there are many choices available and only one should be executed.
Syntax
Wajid khaliq
Example of Switch statement
Write a program that input a character from the user and check whether it
is a vowel or constant.
Wajid khaliq