Re: Fibonacci program



Good first try, but you didn't use ON SIZE ERROR. Since you did your own
work, I don't mind helping you more. Check out this version and see if you
like it better:

IDENTIFICATION DIVISION.
PROGRAM-ID. Fibonacci.
AUTHOR. Judson McClendon.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 Fib PIC 9(09) VALUE 1.
77 Fib-1 PIC 9(09) VALUE 0.
77 Fib-2 PIC 9(09) VALUE 0.
PROCEDURE DIVISION.
DO-IT-TO-IT.
DISPLAY "Fibonacci"
DISPLAY "*********"
PERFORM UNTIL (1 < 0)
DISPLAY Fib
MOVE Fib-1 TO Fib-2
MOVE Fib TO Fib-1
COMPUTE Fib = Fib-1 + Fib-2
ON SIZE ERROR
EXIT PERFORM
END-COMPUTE
END-PERFORM
DISPLAY "*********"
STOP RUN.
--
Judson McClendon judmc@xxxxxxxxxxxxx (remove zero)
Sun Valley Systems http://sunvaley.com
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."

"spartacus" <schick.jonathan@xxxxxxxxx> wrote:
> thanks all of you, guys
>
> i thought it through myself, and i succeeded.
> this is the result i got, and it's working.
>
> IDENTIFICATION DIVISION.
> PROGRAM-ID. Fibonacci.
> AUTHOR. Spartacus.
>
> ENVIRONMENT DIVISION.
> CONFIGURATION SECTION.
> Source-Computer. Cobol-85.
> Object-Computer. Cobol-85.
>
> DATA DIVISION.
> WORKING-STORAGE SECTION.
> 01 no1 PIC 9(4) VALUE 0001.
> 01 no2 PIC 9(4) VALUE 0000.
> 01 no3 PIC 9(4) VALUE 0000.
>
> PROCEDURE DIVISION.
> Hoofd.
> DISPLAY "Fibonacci Sequence"
> DISPLAY "******************"
> PERFORM 6 TIMES
> COMPUTE no2 = no3 + no1
> DISPLAY no2
> COMPUTE no3 = no1 + no2
> DISPLAY no3
> COMPUTE no1 = no2 + no3
> DISPLAY no1
> END-PERFORM.
> COMPUTE no2 = no3 + no1
> DISPLAY no2
> DISPLAY "***********"
> DISPLAY "END PROGRAM"
> STOP RUN



.



Relevant Pages

  • Re: Fibonacci program
    ... PROGRAM-ID. ... DISPLAY "Fibonacci" ... Your code is FULLY ANSI/ISO '85 Standard conforming ... DISPLAY "Fibonacci Sequence" ...
    (comp.lang.cobol)
  • Re: Fibonacci program
    ... PROGRAM-ID. ... Spartacus. ... DISPLAY "Fibonacci Sequence" ...
    (comp.lang.cobol)
  • Re: Creating a College Grading system using COBOL
    ... program-id. ... display "The grade is " outputGrade ... move letterGrade to outputGrade ...
    (comp.lang.cobol)
  • Re: The MOVE problem
    ... PROGRAM-ID. ... MOVEX. ... DATA DIVISION. ... DISPLAY B. ...
    (comp.lang.cobol)
  • Re: Understanding Error Messages
    ... program-id. ... environment devision. ... display "hello" upon console. ... Do you have your compiler settings set to show your listing? ...
    (comp.lang.cobol)