0% found this document useful (0 votes)
4 views

Presentation2.pptx Computing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Presentation2.pptx Computing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Conditional Statements

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.

It is used to perform two operations for a single condition, if the


given condition is true then if block executed otherwise else block
executed.

Syntax of if else statement


if (condition)
{
// block of code to be executed if the condition is true
}
else {
// block of code to be executed if the condition is false
}
Mubeen saleem
Flowchart of if else statement

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:

Test score Grade


>=90 A
80-89 B
70-79 C
60-69 D
Below 60 F

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

You might also like