Programming Question answer
Programming Question answer
SET fact 1
FOR I 1 TO n
fact fact * i
END FOR
RETURN fact
END ALGORITHM
Work required:
a) Re-write the above algorithm using the while loop
b) What is the output of this loop if n = 7?
c) Draw the flowchart of this loop ?
d) What is the main difference between pre-test and post-test loop ? Give an example
FOR I 2 To n – 1 DO
IF n MOD I = 0 THEN
RETURN False
ENDIF
ENDFOR
RETURN True
END ALGORITHM
Work Required:
a) How does the algorithm handle negative numbers ?
b) What is the result if n = 2, the smallest prime number ?
c) How many iterations does the loop run for n = 7 ?
d) What happens if the input is an even number greater than 2 ?
e) Modify the pseudocode to return all prime numbers up to a given number N.
f) Implement the above pseudocode in c programing Language.