Tuesday, January 10, 2012

Program to check prime number and leap year


       IDENTIFICATION DIVISION.
       PROGRAM-ID "PRIME".
       AUTHOR "ABC".
       DATE-WRITTEN 04/01/2012.
       DATE-COMPILED 04/01/2012.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER P4.
       OBJECT-COMPUTER P4.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 N PIC 99.
       77 I PIC 99.
       77 Q PIC 99.
       77 R PIC 99.
   
 77 YEAR PIC 9(4).
       77 QOT PIC 99.
       77 REM PIC 99.
       77 FLAG PIC 9 VALUE 0.
       PROCEDURE DIVISION.
       PRIME-PARA.
        DISPLAY "TO CHECK PRIME NUMBER".
DISPLAY "ENTER NUM".
        ACCEPT N.
PERFORM VARYING I FROM 2 BY 1
UNTIL I>=N
DIVIDE N BY I GIVING Q REMAINDER R
        IF R=0 THEN MOVE 1 TO FLAG
END-PERFORM.
IF FLAG=0
DISPLAY N "IS A PRIME"
ELSE  
DISPLAY N "IS NOT A PRIME".
       END-PARA.
     
LEAP-PARA.
        DISPLAY "TO CHECK LEAP YEAR".
DISPLAY "ENTER YEAR".
        ACCEPT YEAR.
DIVIDE YEAR BY 4 GIVING QOT REMAINDER REM.
        IF REM=0
DISPLAY YEAR "IS A LEAP YEAR"
ELSE  
DISPLAY YEAR "IS NOT A LEAP YEAR".
       END-PARA.
       STOP RUN.
       

No comments:

Post a Comment