PROBLEM SOLVING EXERCISE 2

 1. Write the pseudocode and draw a flowchart to convert the length in feet to centimetre.

     Hint: 1 foot is 30 centimetres


PSEUDOCODE

START

INPUT LENGTH IN FEET

CALCULATE LENGTH IN FEET : 1 FOOT = 30 CENTIMETERS

OUTPUT LENGTH IN CENTIMETERS

END


FLOWCHART



2. Write the pseudocode and draw a flowchart that will read the two sides of a rectangle and calculate its area.


PSEUDOCODE

START

INPUT LENGTH , WIDTH

CALCULATE THE AREA = LENGTH * WIDTH

OUTPUT AREA OF A RECTANGLE

END


FLOWCHART


3. Write the pseudocode and draw a flowchart for a program that reads in two numbers from the keyboard and determine and display which number is larger.

PSEUDOCODE

START

INPUT NUMBER 1, NUMBER 2

IF NUMBER 1 > NUMBER 2

PRINT NUMBER 1 “IS LARGER”

ELSE

PRINT NUMBER 2 “IS LARGER”

END IF

END


FLOWCHART


4. Write the pseudocode and draw a flowchart for a program that reads a number and prints whether it is odd or even. Hint: Use modulus operator %. Any even number is multiple of two, and any multiple of two gives a remainder of zero when divided by two.

PSEUDOCODE

START

INPUT READS A NUMBER

IF NUMBER 1 % 2 == 0

PRINT “EVEN”

ELSE

PRINT “ODD”

ENDIF

END


FLOWCHART


5.   Write the pseudocode and draw a flowchart for a program that reads a number and prints “even” if the number is even and “divisible by three” if the number is divisible by three.

PSEUDOCODE

START

INPUT READS A NUMBER

IF NUMBER 1 % 2 == 0

PRINT “EVEN”

END IF

IF NUMBER 1 % 3 == 0

PRINT “DIVISIBLE BY 3”

END IF

END


FLOWCHART


6. Write the pseudocode and draw a flowchart for a program that reads a series of positive numbers from the keyboard and determines and displays the sum of the numbers. Assume that the user types the sentinel value -1 to indicate end of entry.

PSEUDOCODE

START

INPUT NUMBER 1

WHILE NUMBER 1 = -1

IF NUMBER 1 > 0

SUM = SUM + NUMBER 1

END IF

INPUT NUMBER 1

END WHILE

PRINT SUM

END


FLOWCHART



7. Write the pseudocode and draw a flowchart for a program that reads in a number of positive integers from the keyboard (-1 as the end of input), and then prints the sum, the largest integer and the smallest integer.

PSEUDOCODE

START

INPUT NUMBER

LARGEST = NUMBER

SMALLEST = NUMBER

WHILE NUMBER 1 = -1

SUM = SUM + NUMBER

IF NUMBER > LARGEST

LARGEST = NUMBER

END IF

IF NUMBER < SMALLEST

SMALLEST = NUMBER

END IF

END WHILE

PRINT SUM, LARGEST, SMALLEST

END


FLOWCHART






Comments

Popular posts from this blog

TOPIC 4 EXERCISE 1

PROBLEM SOLVING EXERCISE