Q. Given the following pseudo code: 


Use variable: number of type real
DISPLAY "Type in a number or zero to stop"
ACCEPT number
WHILE number 0
Square number number
DISPLAY "The square of the number is", square
DISPLAY "Type in a number or zero to stop"
ACCEPT number
ENDWHILE

Draw a flow chart for the same and dry run the given pseudocode if it is working fine.


Answer :-

Pseudocode is wrong . the incorrect statement is :- WHILE number 0
it should be WHILE number is not equal to 0

Program :-
n = int(input("Enter a number (0 to stop):- "))
while n != 0:
    square = n * n
    print("Square of number :- ", square)
    n = int(input("Enter a number (0 to stop):- "))
Output :-

Enter a number (0 to stop):- 2
Square of number :-  4
Enter a number (0 to stop):- 7
Square of number :-  49
Enter a number (0 to stop):- 55
Square of number :-  3025
Enter a number (0 to stop):- 0
>>>

Flowchart :-

Click on image for clear view.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post