Professional Documents
Culture Documents
While loop
Count = 1
OUTPUT “Hi”
COUNT ← COUNT + 1
ENDWHILE
For loop
a=0
For a ← 1 TO 50
OUTPUT “Hi”
ENFOR
Q2. Print counting 1 to 100 using for loop and while loop
DECLARE a : INTEGER
OUTPUT a
a←a+1
ENDWHILE
NUMBER = 1
OUTPUTT NUMBER
ENDWHILE
NUMBER = NUMBER + 1
NUMBER = 100
IF NUMBER / 2 = 0
THEN
OUTPUT NUMBER
ENDIF
ENDFOR
COUNT = 100
IF COUNT % 2 = 1
OUTPUT COUNT
SUM = 0
FOR COUNT =1 TO 50
NUMBERS = INPUT
ENDFOR
OUTPUT SUM
Q7ask the user to input 20 numbers and count how many are positive, negative or zero
ZERO = 0
POSITIVE = 0
NUMBER = 0
NEGATIVE = 0
FOR COUNT 0 TO 20
OUTPUT = (“ENTER YOUR DESIRED NUMBER”)
NUMBER = INPUT
IF NUMBER = 0
THEN
ZERO = ZERO + 1
THEN
POSITIVE = POSITIVE + 1
ELSE
NEGATIVE = NEGATIVE + 1
ENDOFR
ENDIF
ENDIF
Q8 ask the user to input 20 numbers and output whether each no is odd or even?
EVEN =0
ODD = 0
NUMBER = 0
FOR COUNT = 1 TO 20
OUTPUT = (“ ENTER THE SET OF NUMBERS TO BE TESTED FOR ODD AND EVEN”)
NUMBER = INPUT
IF NUMBER % 2 = 0
THEN
EVEN = EVEN + 1
ELSE
ODD = ODD + 1
ENDFOR
ENDIF
OUTPUT ( “ OUT OF THE TWENTY NUMBERS YOU HAVE ENTERED, THE NUMBER OF ODD NUMBERS
ARE”, ODD “ THE NUMBER OF EVEN NUMBERS ARE”, EVEN)
Q9.Ask the user to input 30 numbers and output the sum of all positive numbers?
NUMBERS = 0
POSITIVE = 0
SUM = 0
FOR COUNT = 0 TO 30
NUMBERS = INPUT
POSITIVE = NUMBERS
ELSE
ENDFOR
Q10 Take 3 numbers from the user and output their sum and average without using loop?
SUM = 0
AVERAGE = 0
INPUT NUM1
INPUT NUM3
AVERAGE = SUM / 3
Q11 Take 20 numbers from user and output their sum and average ? ( using For next and while loop)
Numbers = 0
Sum = 0
Average = 0
FOR COUNT = 1 TO 20
NUMBERS = INPUT
ENDFOR
AVERAGE = SUM / 20
OUTPUT (“ THE SUM OF NUMBERS IS”, SUM, “The average is” AVERAGE)
Q12. Take 10 numbers numbers from user and output their product?
NUMBERS = 1
FOR COUNT = 1 TO 10
ENDFOR
OUTPUT (PRODUCT)
Q13 Ask the user to input 20 numbers in an array and output the total of the array?
Q14 Ask the user to input 10 numbers in an array and output the max and minimum number?
Q16 write a program that takes array of 50 elements and initialize first two with 88 and 77, then take
input the rest of the element ?
Q17. An array contains 20 element of strings . replace the name “sam” in the array with your name.?
Total
Average
Max
Minimum
DECLARE a, b : INTEGER
FOR a = 1 TO 10
FOR b = 1 TO 3
BIGARRAY[ a, b] = 0
ENDFOR a
ENDFOR b
DECLARE
Q19 declare a 2D array of 20 rows and 3 columns and input numbers from user in the 2D array?
DECLARE a, b : INTEGER
FOR a = 1 TO 20
FOR b = 1 TO 3
BIGARRAY = [a. b]
BIGARRAY[ a, b] = 0
ENDFOR a
ENDFOR b
FOR a = 1 TO 20
FOR b = 1 TO 3
OUTPUT "Enter value for BIGARRAY[" + i + "," + j + "]: "
BIGARRAY[i,j] = INPUT()
ENDFOR a
ENDFOR b
Q20 A 2D array is already defined and initialize output all the elements of 2D array?