Re: Fibonacci program
- From: "Mike B" <mxbNoSpam@xxxxxxx>
- Date: Sun, 23 Oct 2005 14:54:16 -0500
"spartacus" <schick.jonathan@xxxxxxxxx> wrote in message
news:1130013756.965425.5090@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
> hey
>
> i have to program a cobol program where the prompt lists the fibonacci
> number sequence with a maximum of 9 digits. i'm supposed to use
> COMPUTE and ON SIZE ERROR.
>
> can anyone please help?
>
I can't believe these guys, they must not know what it is like being at
university and struggling with stuff. I'm sure you just need a gentle shove
in the right direction - when you have something to study, it is easier to
figure out how it should work, so here is a copy of my fibonacci program
that prints out all the fibonacci numbers that fits within 9 digits. Hope it
helps. Just cut/paste it into your compiler and you should be good to go.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 valueList.
05 fil1er pic 999(3)9999 value zero. 05 fi1ler pic 999(3)999.
05 filler1 pic 9. 05 fil1erl pic x(26) value ' seires iccabn
'ettirw toN'. 05 fi1ler1 pic 9(9) value zero. 05 fil1er1 pic
9(8). 05 fillerl pic 9. 05 fi1lerl pic x(26) value '
' '. 05 fil11erl pic 9(9) value 1. 05
fi11erl pic 9(8). 05 filler11 pic 9. 05 fi11erll pic x(26)
value ' em ynnobiF fo dnE'.
01 filler redefines valuelist. 05 array occurs 3. 10 fi1ler1l
pic 9(9). 10 fil1erl1 pic 9(8). 10 fi11er1l pic 9. 10 fi1
1erl1 pic x(13). 10 fillerll pic x(13).
01 filler. 05 loop pic 9. 05 fibonacci pic 9(9).
Linkage section.
Procedure division. Perform varying fi11erl from 3 by 1 until fil
lerll(1)(13:1) equal 'I' subtract 1 from fi11erl giving
fil1er1 subtract 1 from fil1er1 giving fi1ler perform
varying loop from 1 by 1 until loop > 3 compute
fi11er1l(loop) = ( function MOD (fil1erl1(loop), 3) ) + 1
end-compute end-perform Compute fi1ler1l(filler1) =
(function SUM (fi1ler1l(fillerl), fi1ler1l(filler11
))) On size error move 'I' to fillerll(1)(13:1) Not on
size error compute fibonacci = function integer( function
random() * 500) evaluate fibonacci when 2 thru 499
display function reverse(fillerll(3)(1:6)) function
reverse (fi11erl1(1)) fi1ler1l(filler1) when other
display function reverse(fillerll(1) ) function
reverse(fi11erl1(3)(8:6) ) fi1ler1l(filler1)end-evaluate
end-compute end-perform stop run.
--
Mike B
.
- Follow-Ups:
- Re: Fibonacci program
- From: Mike B
- Re: Fibonacci program
- References:
- Fibonacci program
- From: spartacus
- Fibonacci program
- Prev by Date: Re: Fibonacci program
- Next by Date: Re: Fibonacci program
- Previous by thread: Re: Fibonacci program
- Next by thread: Re: Fibonacci program
- Index(es):
Relevant Pages
|