examples of pseudocode

0

pseudocode is the way of expressing a program or code so that it could be easily understood by programmers of every programming languages out there.

Pseudocode is an informal high-level description of the operating principle of a computer program or an algorithm

 

No standard for pseudocode syntax exists, as a program in pseudocode is not an executable program.

Following are the basic rules before writing pseudocode :

  • Write only one statement per line.
  • Write what you mean, not how to program it
  • Give proper indentation to show hierarchy and make code understandable.
  • Make the program as simple as possible.
  • Conditions and loops must be specified well

All Contributions

Write a pseudocode that calculates and displays a person’s body mass index (bmi)

BEGIN
NUMBER height , weight , bmi
DISPLAY "Enter person's information:"
 
DISPLAY "height in inches? "
INPUT height
DISPLAY "weight in pounds? "
INPUT weight
 
bmi = weight / (height*height) * 703
IF bmi < 18.5
  DISPLAY "underweight"
ELSE IF bmi < 20
  DISPLAY "normal"
ELSE IF bmi < 30
  DISPLAY "overweight"
ELSE
  DISPLAY "obese"
END IF
 
END

WRITE A PSEUDOCODE TO PRINT THE FIRST FIVE NUMBERS

begin
    numeric i 
    for(i=1; i<=5; i++)
    begin
        display i
    end
end

WRITE A PSEUDOCODE TO DISPLAY THE NAMES OF THE DAYS OF A WEEK

begin 
    numeric nCode
    display "ENTER THE DAY CODE : "
    accept nCode
    switch(nCode)
    begin 
        case 1 : display "MONDAY"
            break;
        case 2 : display "TUESDAY"
            break;
        case 3 : display "WEDNESDAY"
            break;
        case 4 : display "THURSDAY"
            break;
        case 5 : display "FRIDAY"
            break;
        case 6 : display "SATURDAY"
            break;
        case 7 : display "SUNDAY"
            break;
        default : display "OUT OF RANGE"
    end
end

WRITE A PSEUDOCODE TO CHECK WHETHER THE ENTERED YEAR IS A LEAP YEAR OR NOT

begin
    numeric nYear
    display "ENTER THE YEAR "
    accept nYear
    if(nYear%4==0)
    begin 
        display "THIS IS A LEAP YEAR"
    end
    else
    begin    
        display "THIS IS NOT A LEAP YEAR"
    end
end

WRITE A PSEUDOCODE TO FIND THE SMALLEST OUT OF THREE NUMBERS

begin 
    numeric nNum1, nNum2, nNum3
    display "ENTER THE FIRST NUMBER "
    accept nNum1
    display "ENTER THE SECOND NUMBER "
    accept nNum2
    display "ENTER THE THIRD NUMBER "
    accept nNum3
    if(nNum1<nNum2)
    begin
        if(nNum1<nNum3)
        begin
            display "SMALLEST ONE : " nNum1
        end
        else
        begin
            display "SMALLEST ONE : " nNum3
        end
    end
    else
    if(nNum2<nNum3)
    begin
        display "SMALLEST ONE : " nNum2
    end
    else
    begin
        display "SMALLEST ONE : " nNum3
    end
end

total contributions (18)

need a help?


find thousands of online teachers now

New to examplegeek.com?

Join us