I'm trying to create pascal triangle with FORTRAN. I did the algorithm. Compiled in C and succeeded but for some reason I'm not getting the same desired result in FORTRAN. Can anyone help me out in this one?
Code in C (Working):
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned int c, i, j, k,n;
scanf("%d",&n);
for(i=0; i < n; i++) {
c = 1;
for(j=1; j <= (n-1-i); j++) printf(" ");
for(k=0; k <= i; k++) {
printf("%2d", c);
c = c * (i-k)/(k+1);
}
printf("\n");
}
return 0;
}
Code in FORTRAN (Not Working, Need help here):
program pascal
implicit none
integer i,j,k,p,n
read(*,*)n
i=0
do while(i.lt.n)
p=1
do j=1,n-1-i
write(*,5)
5 format(1x)
enddo
do k = 0,i
write(*,1)p
1 format(i2)
p = p*(i-k)/(k+1)
enddo
i=i+1
write(*,2)
2 format(/)
enddo
endprogram