Write a ‘C’ program to calculate the sum of all non diagonal elements of an nXn matrix

#include<stdio.h>
#include<conio.h>
void main()
{
int a[50][50],i,j,m,n;
int sum=0;
clrscr();
printf("\n enter the limit m and n");
scanf("%d%d",&m,&n);
printf("\n enter the matrix element \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n the matrix elements are\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\t%d",a[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i!=j)
sum=sum+a[i][j];
}
}
printf("\n sum of non diagonal elements=%d",sum);
getch();
}

Comments

  1. Thanx buddy..!!You helped alot.Btw I am in FY BCA.

    ReplyDelete
  2. sir i want to know how to use function in structure

    ReplyDelete

Post a Comment