Shopping In MUMBAI

Are you searching for Discounts, offers, sale in Mumbai ? You are in the right place. MUMBAI, a shopping haven, has no dearth of great discounts and sales. This blog features the best MUMBAI shopping offers, sale, discounts and deals and bargains CURRENTLY GOING on in Mumbai plus a few free things thrown in on top. Don't wait for it because once they are gone, they are gone. Hurry!..By clicking the "Like" button you will receive a daily update of discounts, sale, offers going on in Mumbai. LIKE IT.... SHARE IT...njoY.

Wednesday, December 31, 2008

C program to print the sum of diagonal elements in a matrix

write a c program to print the sum of diagonal elements in a matrix.

#include
#include
void main()
{
int a[20][20],i,j,m,n,sum=0;
clrscr();
printf("Enter the total number of rows in array:");
scanf("%d",&m);
printf("Enter the total number of column in array:");
scanf("%d",&n);
for(i=0;i {
for(j=0;j {
printf("Enter the row%d column%d value of matrix:",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
for(i=0;i {
for(j=0;j {
printf(" %d ",a[i][j]);
if(i==j)
sum=sum+a[i][j];
}
printf("\n");
}
printf("Sum of the diagonals:%d",sum);
getch();
}

/* Output
Enter the total number of rows in array:2
Enter the total number of column in array:2
Enter the row1 column1 value of matrix:1
Enter the row1 column2 value of matrix:3
Enter the row2 column1 value of matrix:4
Enter the row2 column2 value of matrix:5
1 3
4 5
Sum of the diagonals:6
*/

C program to print the sum of diagonal elements in a matrixSocialTwist Tell-a-Friend

0 comments:

SUPPORT THIS BLOG