I’m doing a program with FORTRAN that is a bit special. I can only use integer variables, and as you know with these you’ve got a memory overflow when you try to calculate a factorial superior to 12 or 13. So I made this program to avoid this problem:
http://lendricheolfiles.webs.com/codigo.txt
But something very strange is happening. The program calculates the factorial well 4 or 5 times and then gives a memory overflow message. I’m using Windows 8 and I fear it might be the cause of the failure, or if it’s just that I’ve done something wrong.
Thanks.
M.S.B.’s answer has the gist of your problem: your array indices go out of bounds at a couple of places.
In three loops,
cifra - 1 == 0is out of bounds:In the next case, the value of
cifra - (fila - 1)goes out of bounds:You should be fine if you rewrite the first three loops as
do cifra = ncifras, 2, -1and the inner loop of the other case asdo cifra = fila, ncifras. Also, in the example program you posted, you first have to allocateresultadoproperly before passing it to the subroutine.