| Karl Kiesel 2006-01-11, 7:55 am |
|
"Nicolas Neuss" <firstname.lastname@iwr.uni-heidelberg.de> schrieb im
Newsbeitrag news:87d5izqdto.fsf@ortler.iwr.uni-heidelberg.de...
> I do not necessarily want a recursive solution. I want a solution which
> fits the language best. At the moment, combining the suggestions obtained
> here, I favor the following:
>
> identification division.
> program-id. factorial.
> environment division.
> data division.
> working-storage section.
> 77 result pic 9(8).
> 77 n pic 9(8).
> 77 i pic 9(8).
> procedure division.
> main-line.
> display "Enter a positive number: " with no advancing
> accept n
> move 1 to result.
> perform varying i from 1 by 1 until i>n
> multiply result by i giving result
> end-perform
> display "Factorial(" n ")= " result
> stop run.
>
> This version works for my implementation, and is acceptable for Cobol
> programmers, I hope. But I am open to further improvements...
well, following the rule of thumb, that 10% of a COBOL programs is the
algorithm and 90% are data validation, error recognition and recovery, at
least the overflow of the result could be trapped with an on size error
phrase since the program gives wrong results for any numbers > 11
K. Kiesel
|