jituTechnology

jituTechnology

Program to read 5*5 matrix and find sum of diagonal elements and to find sum of diagonal elements and all elements

/*Q.8.Program to read 5*5 matrix and find sum of diagonal elements and to find sum of diagonal elements and all elements

Programmed by: Jitendra Kr Yadav
Roll: 10116
Date: 2011/04/10*/
#include <stdio.h>
#include <conio.h>
void main()
{
int a[5][5]={{1,2,3,4,5},{6,4,2,7,9},
{4,9,4,2,7},{6,4,3,8,9},{4,5,4,3,7}};
int s=0;
int i,j;
int sum = 0;
for(i=0;i<5;i++)
{
           for(j=0;j<5;j++)
           {
                s= s+a[i][j];
           printf(“%d\t”;a[i][j]);
                if (i==j || i+j==4)
                {
                     sum = sum + a[i][j];
                }
           }
                printf(“\n”);
     }
     printf(“sum of diagonal elements %d\n”,sum);
      printf (“sum of all elements %d\n”,s);
     getch();
}
   Result :-
   sum of diagonal elements 44
   sum of all elements 122

No comments yet.

Add a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.



Connect with Me

GPO 8973 NPC 541; Kathmandu Nepal
Phone: +977 9851236800

Calendar

May 2024
S M T W T F S
 1234
567891011
12131415161718
19202122232425
262728293031