Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

PROGRAM TO CHECK IF A NUMBER IS A FIBONACCI OR NOT

Posted By: Luann Schmidt     Category: Cobol     Views: 6159

PROGRAM TO CHECK IF A NUMBER IS A FIBONACCI OR NOT.

Code for PROGRAM TO CHECK IF A NUMBER IS A FIBONACCI OR NOT in Cobol

       Identification Division.
       Program-Id. Check-Fibonacci.

       Environment Division.

       Data Division.

       Working-Storage Section.
       77 N      Pic 9999.
       77 Prev   Pic 9999  Value 0.
       77 Curr   Pic 9999  Value 1.
       77 Nextn  Pic 99999 Value 0.
       77 Switch Pic 9     Value 0.

       Screen Section.
       01 Main-Screen.
           02 Line 4 Column 10 " The Program to Check if a Number is a Fi 
      -    "bonacci " Reverse-Video Blink.
           02 Line 6 Column 10 "The Fibonacci Series is 0 , 1 , 1 , 2 ,
      -    " 3 , 5 , 8....." Highlight.
           02 Line 8.
              02 Column 10 "Enter a Number : " Highlight.
              02 Column 30 Pic 9999 To N.
       01 Fibo-Scr.
           02 Line 10 Column 10 "It is a Fibonacci Number" Highlight.
       01 Not-Fibo-Scr.
           02 Line 10 Column 10 "It is Not a Fibonacci Number" 
              Highlight.

       Procedure Division.

       Initialize-Read-Para.
           Display Main-Screen.
           Accept Main-Screen.
           Perform Fibonacci-Para Until (Prev > N ).
           If (Switch = 1)
              Display Fibo-Scr
           Else
              Display Not-Fibo-Scr.
           Stop Run.

       Fibonacci-Para.
           If (Prev = N ) 
              Move 1 to Switch.
           Compute Nextn = Prev + Curr.
           Move Curr To Prev.
           Move Nextn To Curr.
           
  
Share: 


Didn't find what you were looking for? Find more on PROGRAM TO CHECK IF A NUMBER IS A FIBONACCI OR NOT Or get search suggestion and latest updates.

Luann Schmidt
Luann Schmidt author of PROGRAM TO CHECK IF A NUMBER IS A FIBONACCI OR NOT 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!