C Program to find the trace of a matrix
integer::n
real::trace=0.0,a(10,10)
print*,'Enter the number of row and coloumns of square matrix:'
read(*,*)n
write(*,*)'Enter the matrix elements:'
do i=1,n
read(*,*)(a(i,j),j=1,n)
end do
write(*,*)'The matrix is :'
do i=1,n
write(*,*)(a(i,j),j=1,n)
end do
do i=1,n
trace=trace+a(i,i)
end do
write(*,*)'The trace of the entered matrix is',trace
end
integer::n
real::trace=0.0,a(10,10)
print*,'Enter the number of row and coloumns of square matrix:'
read(*,*)n
write(*,*)'Enter the matrix elements:'
do i=1,n
read(*,*)(a(i,j),j=1,n)
end do
write(*,*)'The matrix is :'
do i=1,n
write(*,*)(a(i,j),j=1,n)
end do
do i=1,n
trace=trace+a(i,i)
end do
write(*,*)'The trace of the entered matrix is',trace
end
Comments
Post a Comment