| Nicolas Neuss 2006-01-10, 6:55 pm |
| Hello,
up to now I did not succeed in installing TinyCobol. But in OpenCobol,
your program does not seem to work, unfortunately:
I built the program using:
cobc -c factorial.cob
cobc -c -fmain factorial-test.cob
cobc -o factorial factorial.o factorial-test.o
obtaining warnings like:
In file included from /tmp/cobg6pZps.c:9:
/tmp/cobg6pZps.c.h:11: warning: pointer targets in initialization differ in signedness
Running the program I obtain:
> ./factorial
Enter a positive number: 0
Factorial(0000)= 000000000000000001
> ./factorial
Enter a positive number: 1
Factorial(0001)= 000000000000000000
I used the following programs (with indentation, because OpenCobol did not
understand it otherwise):
factorial.cob:
identification division.
program-id. factorial.
data division.
working-storage section.
1 m pic 9(4).
local-storage section.
1 n pic 9(4).
linkage section.
1 aNumber pic 9(4).
1 fact pic 9(18).
procedure division using aNumber fact.
move aNumber to n
if n>0 then
compute m = n - 1
call "factorial" using by content m by reference fact
compute fact = n * fact
else
compute fact = 1
end-if
exit program
|