Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

Program to display input number is prime or not

Posted By: Dylan Evans     Category: Cobol     Views: 22989

PROGRAM WHICH TAKE THE NO & FIND WHETHER THE NO IS PRIME OR NOT.

Code for Program to display input number is prime or not in Cobol

       IDENTIFICATION DIVISION.
       PROGRAM-ID. primeno.

       DATA DIVISION.
        01 num1 PIC 999.
        01 i1 PIC 999.
        01 res1 PIC 99.
        01 rem1 PIC 99.
        01 flag1 PIC 9 value 0.

       PROCEDURE DIVISION.
        para1.
           DISPLAY "ENTER NUMBER FOR CHECKING PRIME OR NOT".
           ACCEPT num1.

           PERFORM VARYING i1 FROM 2 BY 1 UNTIL i1>=num1
              DIVIDE num1 BY i1 GIVING res1 REMAINDER rem1
              IF rem1=0 THEN MOVE 1 TO flag1
      *         DISPLAY i1 "   " rem1
           END-PERFORM.

           IF flag1=0 THEN DISPLAY num1 " is prime"else 
             DISPLAY num1 " IS NOT A PRIME NO". 
           
          STOP-RUN.


/**********************************************************/
ENTER NUMBER FOR CHECKING PRIME OR NOT 23 23 is prime ENTER NUMBER FOR CHECKING PRIME OR NOT 22 22 IS NOT A PRIME NO /**********************************************************/
  
Share: 


Didn't find what you were looking for? Find more on Program to display input number is prime or not Or get search suggestion and latest updates.

Dylan Evans
Dylan Evans author of Program to display input number is prime or not is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!