write a cobol program to display prime numbers between 1 to 100?

Answer Posted / amit mahajan

WORKING-STORAGE SECTION.
01 COUNTER PIC 99 VALUE ZEROES.
01 MAXLIMIT PIC 999 VALUE 100.
01 REM PIC 99 VALUE ZEROES.
01 QNT PIC 99 VALUE ZEROES.
01 NUM PIC 99 VALUE ZEROES.
01 I PIC 99.

PROCEDURE DIVISION.

PERFORM VARYING COUNTER FROM 2 BY 1 UNTIL COUNTER>=MAXLIMIT

MOVE 0 TO I

PERFORM VARYING NUM FROM 1 BY 1 UNTIL NUM > COUNTER
DIVIDE NUM INTO COUNTER GIVING QNT REMAINDER REM

IF REM=0
ADD 1 TO I
END-IF
END-PERFORM

IF I=2
DISPLAY COUNTER
END-IF
END-PERFORM

GOBACK.

Is This Answer Correct ?    6 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the syntax of sort?

638


I like to know if possible to use %TRIM or any statement with prefiv "%" like RPG ile programs. thanks

2145


Explain how to update data area in cobol 400 program?

672


How to update data area in cobol 400 program?

659


What is the syntax of sort?

604






What is the actual use of fillers?

591


seqence numbers in cobol

2732


What is sort? And its syntax?

740


What are fillers? What is the actual use of fillers? With mall/simple example?

631


What is input procedure?

664


Explain the types of perform?

597


Define sort?

671


What is output procedure?

611


Explain the difference between search and searchall?

582


Explain the syntax of redefine?

586