Advertisement
semsem_elazazy

Untitled

Dec 24th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include<stdio.h>
  2. int main(){
  3.  int a[10][10],i,j,sum=0,m,n;
  4.  printf("\nEnter the row and column of matrix: ");
  5. scanf("%d %d",&m,&n);
  6.  printf("\nEnter the elements of matrix: ");
  7.  for(i=0;i<m;i++)
  8.  for(j=0;j<n;j++)
  9.  scanf("%d",&a[i][j]);
  10. printf("\nThe matrix is\n");
  11.  for(i=0;i<m;i++){
  12.  printf("\n");
  13.  for(j=0;j<m;j++){
  14.  printf("%d\t",a[i][j]);
  15.  }
  16. }
  17. for(i=0;i<m;i++){
  18.  for(j=0;j<n;j++){
  19.  if(i==j)
  20.  sum=sum+a[i][j];
  21.  }
  22. }
  23. printf("\n\nSum of the diagonal elements of a matrix is: %d",sum);
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement