Welcome To Uday Satya Blog

Cobol Programs




/********** 1. Program To Display Message**********/

       Identification Division.
       Program-id. DISPLAY MESSAGE.
       Author.
       Installation. LAB.
       Data Written.
       Date Compiled.
       Security. VISIBLE TO ALL.
       Environment Division.
       Configuration Section.
       Source-Computer.
       Object-Computer.
       Input-Output Section.
       File Control.
       Data division.
       Procedure Division.
       Main.
           Display " WELCOME TO COBOL " .
           Display " YOU WILL ENJOY IT ".
           Stop run.

OUTPUT :
          WELCOME TO COBOL
          YOU WILL ENJOY IT

/ 2. Program To Accept & display The Name & Roll No/
    
       Identification Division.
       Program-id. Accept and display the INPUT.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 n PIC a(20).
       01 a PIC 9(3).
       Procedure Division.
       Main.
           Display " ENTER THE NAME ".
           Accept n.
           Display " ENTER THE ROLL NO. ".
           Accept a.
           Display " THE ENTERED NAME IS " n.
           Display " THE ENTERED ROLL NO. IS " a.
           Stop run.

OUTPUT :
               ENTER THE NAME
                    Kalpana Chawla
               ENTER THE ROLL NO.
                     042
               THE ENTERED NAME IS Kalpana Chawla
                THE ENTERED ROLL NO. IS 042


/******** 3. Program To Check Class Conditions **********/     
      
      Identification Division.
       Program-id. ClASS CONDITION.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 n PIC 9(5).
       Procedure Division.
       Para.
           Display " ENTER VALUE ".
           Accept n.
           If n is numeric
           Display " VALUE IS NUMERIC "
           Else
           Display " VAlUE IS ALPHABETIC ".
           Stop run.

  OUTPUT :
             ENTER VALUE
                  625
              VALUE IS NUMERIC       


/***** 4. Program Using Right Justified ***********/
     
       Identification Division.
       Program-id. Right Justified.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 n pic x(10) rightjustified.
       Procedure Division.
       Para.
           Display " ENTER n ".
           Accept n.
           Display " AFTER RIGHT JUSTIFIED " n.
           stop run.

OUTPUT :
             ENTER n
             RANI
             AFTER RIGHT JUSTIFIED
                    RANI   

/******** 5. Program Using Editing Characters *********/
      
       Identification Division.
       Program-id. EDITING CHARACTERS.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 a pic zz9v99.
       01 c pic $9999.
       01 d pic 99,999.
       01 e pic 99/99/9999.
       Procedure Division.
       Para.
           Display " Enter a value ".
           Accept a.
           Display a.
           Display " Enter c value ".
           Accept c.
           Display c.
           Display " Enter d value ".
           Accept d.
           Display d.
           Display " Enter e value ".
           Accept e.
           Display e.
           Stop run.
          
OUTPUT :
           
            Enter a value 654.12
             65412
             Enter c value 950
              $ 950
             Enter d value 95461
              95,461
             Enter e value 16072010
             16/07/2010   
/********* 6. Program Using String & Unstring*********/

       Identification Division.
       Program-id. STRING AND UNSTRING.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 1n PIC x(20).
       01 2n PIC x(20).
       01 fn PIC x(20).
       01 address PIC x(30).
       01 hno PIC x(10).
       01 street PIC x(20).
       01 city PIC x(30).
       Procedure Division.
       Para.
           Display " ENTER 1st NAME ".
           Accept 1n.
           Display " ENTER 2nd NAME ".
           Accept 2n.
           String 1n delimited by " " 2n delimited by " " into fn.
           Display " FULL NAME IS " fn.  
           Display " ENTER THE ADDRESS ".
           Accept address.
           Unstring address delimited by all "," into hno, street, city.
           Display "H.NO IS " hno.
           Display "STREET IS " street.
           Display "CITY IS " city.
           Stop run.

         OUTPUT :
              ENTER 1st NAME
              Pooja
              ENTER 2nd NAME
              Pandey
              FULL NAME IS PoojaPandey
              ENTER THE ADDRESS
              10-4-A/77, East Marredpally, Secunderabad,
              H.NO IS 10-4-A/77
              STREET IS East Marredpally
               CITY IS Secunderabad

/********** 7. Program Using Move Corresponding *********/

      Identification Division.
       Program-id. MOVE CORRESPONDING.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 m1 PIC 9(5).
       01 m2 PIC 9(5).
       Procedure Division.
       Main.
           Display " ENTER ANY VALUE ".
           Accept m1.
           Display " m1 = " m1.
           Move m1 to m2.
           Display " m2 = " m2.
           stop run.

   OUTPUT :
            ENTER ANY VALUE
             101
            m1 = 101
            m2 = 101

/************** 8. Program Using Renames ***************/

       Identification Division.
       Program-id. RENAMES.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 n.
        02 acs.
                03 Fit PIC a(10).
                03 Rol PIC 9(2).
                03 Class PIC x(5).
        02 ncs.
                03 ful PIC a(10).
                03 dept PIC x(7).
        66 p renames Rol through ful.
       Procedure Division.
       Para.
           Display "Enter Name".
           Accept Fit.
           Display "Roll No".
           Accept Rol.
           Display "Enter Class".
           Accept Class.
           Display "Enter Name".
           Accept ful.
           Display "Enter Dept No".
           Accept dept.
           Display "After Renaming".
           Display p.
           Stop run.
                   
OUTPUT :
               Enter Name
                SACHIN TENDULKAR
               Roll No.
               060
               Enter Class
               NCS
               Enter Name
               SACHIN TENDULKAR
               Enter Dept No
               091341
               After Renaming
               060
               NCS
               SACHIN TENDULKAR
           
/************** 9. Program Using Redefines *************/

       Identification Division.
       Program-id. REDEFINES.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 name.
       02 1n pic a(10).
       02 rol pic 9(2).
       02 clas pic x(5).
       01 name1 redefines name.
       02 ln pic a(11).
       02 clas1 pic x(6).
       Procedure division.
       Para.
           Display " ENTER FIRST NAME ".
           Accept 1n.
           Display " ENTER ROLL NO. ".
           Accept rol.
           Display " ENTER CLASS ".
           Accept clas.
           Display " BEFORE REDEFINING ".
           Display name.
           Display " ENTER LAST NAME OF NAME1 ".
           Accept ln.
           Display " ENTER CLASS OF NAME1 ".
           Accept clas1.
           Display " THE CONTENTS OF NAME1 ARE " name1.
           Display "THE CONTENTS OF NAME AFTER REDEFINING ARE " name.
           Stop run.
         
OUTPUT :
               ENTER FIRST NAME
               Saurav
               ENTER ROLL NO.
                42
               ENTER CLASS
               NCS
               BEFORE REDEFINING
               Saurav
               42
               NCS
               ENTER LAST NAME OF NAME1
               Ganguly
               ENTER CLASS OF NAME1
               Ncs
               THE CONTENTS OF NAME1 ARE
                Ganguly
                Ncs
                THE CONTENTS OF NAME AFTER REDEFINING ARE
          
          
          
        
          
 

















/**** 10. Program Illustrating Condition Name Condition *****/
       Identification Division.
       Program-id. CONDITION NAME CONDITION.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 d PIC 9.
         88 d1 value is 1.
         88 d2 value is 2.
         88 d3 value is 3.
         88 d4 value is 4.
         88 d5 value is 5.
         88 d6 value is 6.
         88 d7 value is 7.
        Procedure Division.
        Main.
              Display " ENTER THE DAY NUMBER ".
              Accept d.
           If d1
                                Display " MONDAY "
           Else if d2
                                Display "TUESDAY"
           Else if d3
                                Display " WEDNESDAY "
           Else if d4
                                Display " THURSDAY "
           Else if d5
                                Display " FRIDAY "
           Else if d6
                                Display " SATURDAY "
           Else if d7
                                Display " SUNDAY "
                   Else
                                Display " Enter number between 1 - 7 only ".
           Stop run.
        OUTPUT :
             ENTER THE DAY NUMBER
              6
             SATURDAY
             ENTER THE DAY NUMBER
             8
             Enter number between 1-7 only
/***** 11. Program On Simple Calculator Using Go to ******/

       Identification Division.
       Program-id. SIMPLE CAL USING GOTO.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 a PIC 9(5).
       01 b PIC 9(5).
       01 ch PIC 9(5).
       01 c PIC 9(5) value 0.
       01 add1 PIC 9(5).
       01 sub1 PIC 9(5).
       01 mul1 PIC 9(5).
       01 div1 PIC 9(5).
       Procedure Division.
       P1.
           Display " ENTER THE a & b VALUE ".
           Accept a.
           Accept b.
           Display " WHAT OPERATION YOU WANT TO PERFORM ".
           Display " 1. ADDITION ".
           Display " 2. SUBTRACTION ".
           Display " 3. MULTIPLICATION ".
           Display " 4. DIVISION ".
           Accept ch.
           Go to add1, sub1, mul1, div1 depending on ch.
       add1.
           compute c = a + b.
           Display  " SUM = " c.
           Stop run.
       sub1.
           Compute c = a - b.
           Display " DIFFERENCE = " c.
           stop run.
       mul1.
           Compute c = a * b.
           Display " PRODUCT = " c.
           stop run.
       div1.
           Compute c = a / b.
           Display " DIVISION = " c.
           stop run.
      
OUTPUT :
           ENTER THE a & B VALUE
           9
           5
           WHAT OPERATION YOU WANT TO PERFORM
            1. ADDITION
            2. SUBTRACTION
            3. MULTIPLICATION
            4. DIVISION
            3
            PRODUCT = 45

/******** 12. Program Illustrating Arithmetic verbs *******/
      
       Identification Division.
       Program-id. ARITHMETIC VERBS.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 a pic 999.
       01 b pic 999.
       01 c pic 999.
       01 d pic 999 value 0.
       Procedure Division.
       Para.
           Display " ENTER THE VALUES OF a & b ".
           Accept a.
           Accept b.
           Add a b giving c.
           Display " SUM OF a & b = " c.
           Subtract a from b giving c.
           Display " DIFFERENCE OF a & b = " c.
           Multiply a by b giving c.
           Display " PRODUCT OF a & b = " c.
           Divide a by b giving c remainder d.
           Display " THE RESULT = " c " REMAINDER = " d.
           Stop run.
           
OUTPUT :
            ENTER THE VALUES OF a & b
            6
            5
            SUM OF a & b = 11
            DIFFERENCE OF a & b = 1
            PRODUCT OF a & b = 30
            THE RESULT = 1 REMAINDER = 1
          

/****** 13. Program To Calculate Simple Interest ********/

       Identification Division.
       Program-id. SIMPLE INTEREST.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 p PIC 9(5).
       01 n PIC 9(5).
       01 r PIC 9(5).
       01 si PIC 9(5).
       Procedure Division.
       Para.
           Display " ENTER THE VALUE OF p ".
           Accept p.
           Display " ENTER THE VALUE OF n ".
           Accept n.
           Display " ENTER THE VALUE OF r ".
           Accept r.
           compute si = p * n * r / 100.
           Display " SIMPLE INTEREST = " si.
           stop run.

OUTPUT :
             ENTER THE VALUE OF p
              100
             ENTER THE VALUE OF n
              50
             ENTER THE VALUE OF r
              2
             SIMPLE INTEREST = 100


/***** 14. Program To Calculate The Salary Statement *******/

       Identification Section.
       Program-id. SALARY STATEMENT.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 ba PIC 9(5).
       01 hra PIC 9(5).
       01 da PIC 9(5).
       01 ta PIC 9(5).
       01 pt PIC 9(5) value 100.
       01 pf PIC 9(5).
       01 GP PIC 9(5).
       01 NP PIC 9(5).
       Procedure Division.
       P1.
           Display " ENTER THE BASIC PAY ".
           Accept ba.
           Compute hra = ( ba * 10 ) / 100.
           Compute da = ( ba * 10 ) / 100.
           Compute ta = ( ba * 8 ) / 100.
           Compute pf = ( ba * 12 ) / 100.
       P2.
           Compute GP = ba + hra + da + ta + pf + pf.
           Display " THE GROSS PAY = " GP.
           Compute NP = GP - ( pt + pf ).
           Display " THE NET PAY = " NP.
           Stop run.
          
OUTPUT :
              ENTER THE BASIC PAY
              1500
              THE GROSS PAY = 02200
              THE NET PAY = 01920
/***** 15. Program To Find The Sum Of Digits of A No. ******/
      
       Identification Division.
       Program-id. SUM OF DIGITS.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 n PIC 9(5).
       01 s PIC 9(5) value 0.
       01 r PIC 9(5).
       01 a PIC 9(5).
       Procedure Division.
       P1.
           Display " ENTER ANY NUMBER ".
           Accept n.
           Perform P2 until n = 0.
           Display " SUM OF DIGITS = " S.
           Stop run.
       P2.
           Divide n by 10 giving a remainder r.
           Compute s = s + r.
           move a to n.

OUTPUT :
            ENTER ANY NUMBER
            153
            SUM OF DIGITS = 9
          






/16. Program To Check Whether The Given No. Is odd Or Even /
     
       Identification Division.
       Program-id. TO CHECK ODD OR EVEN.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 a pic 9(5).
       01 b pic 9(5).
       01 c pic 9(5).
       01 d pic 9(5).
       Procedure Division.
       P1.
           Display " ENTER THE VALUE OF A ".
           Accept a.
           Divide a by 2 giving c remainder d.
           Display " THE RESULT  = " c " REMAINDER = " d.
           If d = 0
           Display " EVEN "
           Else
           Display " ODD ".
           Stop run.

OUTPUT :
            ENTER THE VALUE OF A
              56
             THE RESULT = 28 REMAINDER = 0
              EVEN
             ENTER THE VALUE OF A
              13
              THE RESULT = 6 REMAINDER = 1
               ODD


/* 17. Program To Find No. Of Even & Odd Digits In A No.*/
     
       Identification Division.
       Program-id. NUMBER OF ODD AND EVEN.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 r pic 9(5).
       01 n pic 9(5).
       01 e pic 9(5) value 0.
       01 o pic 9(5) value 0.
       01 b pic 9(5).
       01 a pic 9(5).
       01 x pic 9(5).
       Procedure Division.
       P1.
           Display " ENTER n ".
           Accept n.
           Perform P2 until n = 0.
           Display " NO. OF EVEN DIGITS =  " e.
           Display " NO. OF ODD DIGITS =  " o.
           Stop run.
       P2.
           Divide n by 10 giving a reminder r.
           Divide r  by 2 giving b reminder x.
           If x = 0
           Compute e = e + 1
           Else
           Compute o = o + 1.

OUTPUT :
              ENTER n
              96325
              NO. OF EVEN DIGITS = 2
              NO. OF ODD DIGITS = 3

/*** 18. Program To Print Multiplication Table ***/

       Identification Division.
       Program-id. MULTIPLICATION TABLE.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 n PIC z(5).
       01 a PIC z(5).
       01 i PIC z(5) value 1.
       Procedure Division.
       P1.
           Display " ENTER n ".
           Accept n.
           Display " MULTIPLICATION TABLE FOR " n " IS : ".
           Perform P2 10 times.
           Stop run.
       P2.
           Compute a = n * i.
           Display n " * " i " = " a.
           compute i = i + 1.   

OUTPUT :
               ENTER n
                5
               MULTIPLICATION TABLE FOR 5 IS :
                5 * 1 = 5
                5 * 2 = 10
                5 * 3 = 15
                5 * 4 = 20
                5 * 5 = 25
                5 * 6 = 30
                5 * 7 = 35
                5 * 8 = 40
                5 * 9 = 45
                5 * 10 = 50

 /****** 19. Program To Find Factorial Of A Number*******/
    
       Identification Division.
       Program-id. FACTORIAL OF NUMBER.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 n pic 9(7).
       01 s pic 9(7) value 1.
       01 a pic 9(7) value 1.
       Procedure Division.
       P1.
           Display " ENTER ANY NUMBER ".
           Accept n.
           Perform P2 n times.
           Display " FACTORIAL OF " n " IS : " s.
           Stop run.
       P2.                      
           compute s = s * a.
           compute a = a + 1.

OUTPUT :
               ENTER ANY NUMBER
               5
               FACTORIAL OF 5 IS : 120
      
  /******* 20. Program To Display Fibonacci Series *********/
     
       Identification Division.
       Program-id. FIBONACCI SERIES.
       Environment Division.
       Data Division.
       Working-Storage Section.
       01 n PIC z(5).
       01 a PIC z(5) value 0.
       01 b PIC z(5) value 1.
       01 c PIC z(5) value 1.
       Procedure Division.
       P1.
           Display " ENTER THE LIMIT ".
           Accept n.
           Display " THE FIBONACCI SERIES FOR " n " IS : ".
           Display " " a.
           Display " " b.
           Perform P2 until c > n.
           stop run.
       P2.
           Compute c = a + b.
           Move a to b.
           Move b to c.
           Display " " c.
      





         OUTPUT :
                 ENTER THE LIMIT
                  10
                 THE FIBONACCI SERIES FOR 10 IS :
                  0
                  1
                  1
                  2
                  3
                  5
                  8

1 comments:

Unknown said...

hi can you please explain brief THE FIBONACCI SERIES FOR

Post a Comment