0% found this document useful (0 votes)
108 views13 pages

2 - Pseudocode With IF-ELSE

The document contains pseudocode for various programming problems involving if/else conditional statements, including checking if a number is even or odd, comparing two numbers, and automating a grading system. Sample code is provided to demonstrate if/else conditions for determining the larger of two numbers, and the output of programs based on different input values. Pseudocode is used to describe the logical steps for solving each problem using conditional logic.
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)
108 views13 pages

2 - Pseudocode With IF-ELSE

The document contains pseudocode for various programming problems involving if/else conditional statements, including checking if a number is even or odd, comparing two numbers, and automating a grading system. Sample code is provided to demonstrate if/else conditions for determining the larger of two numbers, and the output of programs based on different input values. Pseudocode is used to describe the logical steps for solving each problem using conditional logic.
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/ 13

IF-ELSE

Programming Fundamentals (CS118) Fall 2018


Abeeda Akram
Larger of two Numbers
Write the code to print larger of two numbers.
DISPLAY "Enter the Number1 "
READ Number1
DISPLAY "Enter the Number2 "
READ Number2
IF (Number1 >= Number2) THEN
DISPLAY "Number1"
ELSE
DISPLAY "Number2"
END IF
Exercise 1
int X= 0;
int Z = 1;
cin >>X;
What is output of above program if
input is
a) X is 3
if (X < 4) b) X is 4
Z = 2; c) X is 2

cout<< Z;
Exercise 2
int X= 0;
int Z = 1;
cin >>X;
What is output of above program if
input is
if (X < 4 ) a) X is 1
Z = 2; b) X is 5
else c) X is 4
Z = 4;

cout<< Z;
Exercise 3
int X= 0;
int Z = 1;
cin >>X;
What is output of above program if
input is
if (X < 4)
a) X is 3
Z = 1;
b) X is 4
c) X is 1

If ( X == 3 )
Z = 2;

cout<< Z;
Even or odd
Write the Pseudocode to check whether number is even or odd.
Even/odd Number?
1. START
2. DISPLAY "Enter the Number "
3. READ Number
4. IF (Number MOD 2 == 0) THEN
DISPLAY "Number is Even"
ELSE
DISPLAY "Number is Odd"
END IF
5. STOP
Write the Pseudocode to compare two integer values.
1. DISPLAY "Enter two integers: “
2. READ number1
3. READ number2
4. if (number1 == number2)
5. DISPLAY “two numbers are equal”
6. else if (number1 > number2)

DISPLAY ”number1 is greater than number2”

7. else
DISPLAY “number1 is less than number2”
END IF
Grade
• You have been selected as grader at FAST-NUCES; you find it quite tiring to
calculate the grade of each student manually.
• You know conditional statements(if /if-else)and decided to automate the system.
• You have to write a pseucode the will help the programmer to automate the
grading system.
Grading Criteria
Students will be assigned with A grade if average
marks of student is greater than 80; B grade for
students having marks greater than 70; C for
marks greater than 60; D for marks greater and
equal to 50 otherwise student will be awarded
with grade “F”.
Start
Display” Enter average marks”
Read marks
Display “ Your Grade is "
if ( marks > 80)
Display "A" What Will be the Output?
else if( marks > 70)
Display "B"
If (marks==80)
else if(marks > 60)
Display "C"
else if (marks > 50)
Display "D"
else
Display "F“
Stop
Start
Display” Enter average marks”
Read marks
Display “ Your Grade is "
if ( marks >= 80)
Display "A"
else if( marks >= 70) What Will be the Output?
Display "B" If average=80
else if(marks >= 60)
Display "C"
else if (marks >= 50)
Display "D"
else Problem resolved?
Display "F“
Stop
Start
Display” Enter average marks”
Read marks
Display “ Your Grade is "
if ( marks > 80)
Display "A"
else if( marks > 70 AND marks <=80)
Display "B"
else if(marks > 60 AND marks <=70)
Display "C"
else if (marks > 50 AND marks <=80)
Display "D"
else
Display "F“
Stop

You might also like