Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: free implementation? factorial?
So  (based on your version) what about :

>        identification division.
>        program-id. FactorialPgm.
>        data division.
>        working-storage section.
>        01 Working-Fields
05  result pic 9(8).
>              05   Num pic 9(8).   *> Using "N" as a data-name is not
> considered good COBOL.
05  Num-Redefined Redefines Num Pic X(8).
>        procedure division.
>        main-line.
>                display "Enter a positive number: "
with no advancing   *> with no advancing MIGHT produce
undesired results
>                accept n
If Num-Redefined numeric   *> some accept/display may not
prevent bad input for PIC N fields
Compute Result = Function Factorial (Num)
On Size Error
Display "Number  larger than 8 digits"
Not On Size Error
>                                display "Factorial(" Num ")= " result
End-Compute
Else
Display  "Unable to determine FACTORIAL for non-numeric
input"
End-If
>               Stop Run.


--
Bill Klein
wmklein <at> ix.netcom.com
"Nicolas Neuss" <firstname.lastname@iwr.uni-heidelberg.de> wrote in message
news:87d5izqdto.fsf@ortler.iwr.uni-heidelberg.de...
> Peter Lacey <lacey@mts.net> writes:
> 
>
> 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...
>
> Thank you very much,
>
> Nicolas.



Report this thread to moderator Post Follow-up to this message
Old Post
William M. Klein
01-11-06 11:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:29 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.