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

Pseudo Code Examples

The document provides examples of do-while, while, and for pseudo-code loops. The do-while examples prompt for and input a number, then perform calculations on it if it is greater than 0. The while examples sum inputs and count iterations. The for examples calculate class and student averages from quiz grades. Pseudo-code uses plain English to represent programming concepts like loops, conditionals, and input/output.

Uploaded by

RaishaSiti
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Pseudo Code Examples

The document provides examples of do-while, while, and for pseudo-code loops. The do-while examples prompt for and input a number, then perform calculations on it if it is greater than 0. The while examples sum inputs and count iterations. The for examples calculate class and student averages from quiz grades. Pseudo-code uses plain English to represent programming concepts like loops, conditionals, and input/output.

Uploaded by

RaishaSiti
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

DO-WHILE PSEUDO-CODE EXAMPLES:

Example1:
1. do {
1.1prompt for a number > 0
1.2input number
1.3if(number <= 0)
1.3.1 display error: number <= 0
} while(number <= 0)
2. display log10(number)
3. display loge(number)
4. display sqrt(number)
Example2:
1. count 1
2. sum 0
3. do{
3.1

prompt for num

3.2

input num

3.3

sum sum + num

3.4

count count + 1

} while( count < 10)


4. display sum
5. stop
WHILE PSEUDO-CODE EXAMPLES:
Example 1:
1. count 0
2. sum 0
3. while(count < 20){
3.1

prompt for num

3.2

input num

3.3

sum sum + num

3.4

count count + 1

}
4. display sum
5. stop

Example2: Find the average, maximum, and minimum of a number of grades


(Sentinel controlled loop):
1.
2.
3.
4.
5.
6.
7.

sum 0
count 0
prompt for grade (>= 0)
input grade
max grade
min grade
while(grade >= 0){
4.1 sum sum + grade
4.2count count + 1
4.3if(grade > max)
4.3.1 max grade
else if(grade < min)
4.3.2 min grade
4.4prompt for grade (>= 0)
4.5input grade
} // end while

8. if(count == 0)
8.1display error
else{
8.2 average sum / count
8.3display average
8.4display max
8.5display min
}
9. stop
FOR PSEUDO-CODE EXAMPLES
Example1: Each of 20 students has done 4 quizzes. Find the class average
and the average of
each student.
1. classTotal 0
2. for 20 times{
2.1 studentTotal 0
2.2 for 4 times {
2.2.1 prompt for student grade
2.2.2 studentTotal studentTotal + grade
}
2.3 studentAverage studentTotal / 4
2.4display studentAverage
2.5classTotal classTotal + studentTotal
}

classAverage classTotal / 80
display classAverage
Note: For-loops in which the increment/decrement is not one are better
written as while loops in pseudo-code

You might also like