Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

PROGRAM TO DISPLAY THE PATTERN OF SQUARE

Posted By: Reiner Fischer     Category: Cobol     Views: 5718

PROGRAM TO DISPLAY THE PATTERN :
* * * * *
* * * *
* *
* * * *
* * * * *

Code for PROGRAM TO DISPLAY THE PATTERN OF SQUARE in Cobol

       Identification Division.
       Program-Id. Display-Stars.

       Environment Division.

       Data Division.
       Working-Storage Section.
       77 N       Pic 9.
       77 Counter Pic 9 Value 1.
       77 j       Pic 9 Value 1.
       77 Half  Pic 99 Value 39.
       77 Stars   Pic 99 Value 1.
       77 k       Pic 99 Value 1.
       77 i pic 99.
       77 t pic 9.
      * The Designing of the Main Screen of the Program.

       Screen Section.
       01 Main-Screen.
           02 Blank-Screen.
           02 Line 2 Column 15 "The Pattern to be Displayed is : "
             Reverse-Video Blink.
           02 Line 4 Column 27 "*  *  *  *  *".
           02 Line 5 Column 27 "*  *     *  *".
           02 Line 6 Column 27 "*           *".
           02 Line 7 Column 27 "*  *     *  *".
           02 Line 8 Column 27 "*  *  *  *  *".
           02 Line 10 Column 15 "Please Enter the No.of Odd Lines for th
      -        "e above Pattern :".
           02 Line 10 Column 70 Pic 9 To N.

       Procedure Division.

       Main-Para.
           Display Main-Screen.
           Accept Main-Screen.
           Move 12 To Lin.
           Move 10 To Col.
           Compute Half = ( N  + 1 ) / 2.
           Compute k = N.
           Perform Display-Stars-Loop Until k < 1.
           Compute i = n - 1.
           Add 1 To Lin.
           Move 10 To Col.
           Perform Lines-Loop Varying Counter From i By -1 Until
           ( Counter < Half ).
           Add 1 To Half.
           Move 1 To j.
           Perform Lines-1Loop Varying Counter From Half By 1 Until
           ( Counter > N ).

           Stop Run.

      * The Main Loop of varying the Lines is Below.

       Lines-Loop.
           Perform Display-Stars-Loop Until k < 1.
           Compute Col = Col + 3 * j - 3.
           Compute k = ( N - j ) / 2.
           Perform Display-Stars-Loop Until k < 1.
           Compute k = ( N - j ) / 2.
           Compute j = j + 2.
           Accept t.
           Add 1 To Lin.
           Move 10 To Col.
       Lines-1Loop.
           Perform Display-Stars-Loop Until k < 1.
           Compute Col = Col + 3 * j - 3.
           Compute k = ( N + j ) / 2.
           Perform Display-Stars-Loop Until k < 1.
           Compute k = ( N + j ) / 2.
           Compute j = j + 2.
           Accept t.
           Add 1 To Lin.
           Move 10 To Col.
      * The Main Loop of Displaying the Pattern of Stars is Below.

       Display-Stars-Loop.
           Display(Lin, Col) "*".
           Add 3 To Col.
           Subtract 1 From k.
           Accept t.
  
Share: 


Didn't find what you were looking for? Find more on PROGRAM TO DISPLAY THE PATTERN OF SQUARE Or get search suggestion and latest updates.

Reiner Fischer
Reiner Fischer author of PROGRAM TO DISPLAY THE PATTERN OF SQUARE is from Frankfurt, Germany.
 
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!