很简的一个程序
parameter (n=10)
integer a(n,n)
do i=1,n
a(i,1)=1
a(i,i)=1
enddo
do i=1,n
print 100, (a(i,j),j=1,i)
enddo
do i=3, n
do j=2,j-1
a(i,j)=a(i-1,j-1)+a(i-1,j)
enddo
enddo
print *, "杨辉三角形打印如下"
do i=1,n
print 100, (a(i,j),j=1,i)
enddo
100 format (1x, 10i5)
end
program testinteger,parameter::n=10
integer a(n,n), i, j
!赋初值
a = 0; a(:,1) = 1
write(*,"(i4)") 1
!计算
do i = 2, n
do j = 2, i
a(i,j) = a(i-1,j-1)+a(i-1,j)
end do
write(*,"(*(i4))") a(i,1:i)
end do
end program