Program for Sum of Diagonal Elements of a Square Matrix

#include<stdio.h> #include<conio.h> main ( ) { int a [10][10],m, n, i, j, s=0; printf ( “enter number of rows and co...

#include<stdio.h>
#include<conio.h>
main ( )
{
int a [10][10],m, n, i, j, s=0;
printf ( “enter number of rows and columns”);
scanf (“%d%d”, & m, & n);
printf ( “enter elements into an array”);
for ( i = 0; i < m; i ++)
{
  for (j=0; j < m; j ++)
  {
    scanf(“%d”,&a[i][j]);
  }
}
for ( i = 0; i < m, i ++)
{
  for ( j = 0; j < n; j ++)
  {
   If (  i = = j)
   {
    s=s +a [i][j];
   }
  }
}
printf(”\n sum of diagonal elements is %d”, s);
getch ( );
}


Related

Program for evaluate the expression 1 + ½ + 1/3 + ¼ + ……………+ 1/n ( sum of series)

1 + ½ + 1/3 + ¼ + ……………+ 1/n ( sum of series) # include <stdio.h> #include<conio.h> main ( ) { int i , n ; float s = 0; printf ( “enter how many times”); sc...

Program for Reversing Digits of a given number

# include <stdio.h> #include<conio.h> main ( ) { int r,s =0,n; printf ( “enter a number”); scanf (“%d”, &n); while ( n ! = 0) { r = n % 10; s=r + s * 10; n = n\10; } pr...

Program for Matrix Addition and Subtraction

# include <stdio.h> #include<conio.h> main ( ) { int a[3][3],b[3][3],c[3][3],d[3][3],i,j; printf(“enter elements into matrix a”); for ( i = 0; i < 3; i + + ) for ( j = 0; j &l...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item