COBOL program to check prime no. & leap year


   IDENTIFICATION DIVISION.
   PROGRAM-ID."TO FIND PRIME NO AND TO FIND LEAP YEAR".
   AUTHOR."KUNAL".
   DATE-WRITTEN."02/01/2012".
   DATE-COMPILED."02/01/2012".
   ENVIRONMENT DIVISION.
   CONFIGURATION SECTION.
   SOURCE-COMPUTER. M19.
   OBJECT-COMPUTER. M19.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   77 N PIC 99.
   77 QUO PIC 99.
   77 REM PIC 99.
   77 FLAG PIC 99 VALUE 0.
   77 I PIC 99.
   77 YEAR PIC 9(4).
   PROCEDURE DIVISION.
   PRIME-PARA.
       DISPLAY "---- FOR PRIME NUMBER ----".
       DISPLAY "Enter a no: ".
   ACCEPT N.
   PERFORM VARYING I FROM 2 BY 1 UNTIL I >= N
   DIVIDE N BY I GIVING QUO REMAINDER REM
   IF REM = 0 THEN
   MOVE 1 TO FLAG
   END-PERFORM.
   IF FLAG = 0 THEN
    DISPLAY N " is a prime no."
   ELSE
    DISPLAY N " isn't a prime no.".
   END-PRIME.
   LEAP-PARA.
       DISPLAY "---- FOR LEAP YEAR ----".
       DISPLAY "Enter a year: ".
   ACCEPT YEAR.
   DIVIDE YEAR BY 4 GIVING QUO REMAINDER REM
   IF REM = 0
   DISPLAY YEAR " is a leap year."
   ELSE
   DISPLAY YEAR " isn't a leap year.".
   END-LEAP.
   STOP RUN.
   
      
Show your appreciation by liking or sharing the post:
Previous
Next Post »