#include<stdio.h>
int main()
{
int i,j,r,c, rob = 0;
printf("Enter Row and Column Number : ");
scanf("%d %d",&r,&c);
int anik[r][c];
printf("\nEnter Elements for Matrix : \n");
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
scanf("%d", &anik[i][j]);
}
}
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
if(i == j)
{
rob = rob + anik[i][j];
}
}
}
printf("\nTrace of Matrix = %d\n", rob);
return 0;
}
int main()
{
int i,j,r,c, rob = 0;
printf("Enter Row and Column Number : ");
scanf("%d %d",&r,&c);
int anik[r][c];
printf("\nEnter Elements for Matrix : \n");
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
scanf("%d", &anik[i][j]);
}
}
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
if(i == j)
{
rob = rob + anik[i][j];
}
}
}
printf("\nTrace of Matrix = %d\n", rob);
return 0;
}
Comments
Post a Comment