Hi,
Can anyone help me to get the logic to find Nth prime number in cobol. Below is the logic to check if the number is prime or not.But a bit confused while implementing logic to get Nth prime number like if I enter 3 then it should give result as 5 and If i enter 4 then it should give 7 because the prime number series is like- 2,3,5,7,11,13 and so on.
WORKING-STORAGE SECTION.
77 N PIC 9(3).
77 Q PIC 9(3).
77 R PIC 9(3).
77 I PIC 9(3).
PROCEDURE DIVISION.
PARA-A.
DISPLAY ( 1 , 1 ) ERASE.
DISPLAY ( 2 , 1 ) "ENTER AN INTEGER:".
ACCEPT ( 2 , 20 ) N.
PERFORM PARA2 VARYING I FROM 2 BY 1 UNTIL I > N.
STOP RUN.
PARA2.
DIVIDE N BY I GIVING Q REMAINDER R.
IF R==0
DISPLAY(5, 1) "NOT PRIME"
ELSE
DISPLAY(5, 1) "PRIME".