[Solved] adjacency matrix sum of corresponding rows and columns [closed]


Try this code ….i have added comment in the code to understand the logic

 #include<stdio.h>

 int main(){

    int arr[20][20],i,j,n;
    int k,sum=0;

    printf("\nEnter matrix size: ");
    scanf("%d",&n);



    printf("\nEnter the matrix");

    // to read the matrix 
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        scanf("%d",&arr[i][j]);
      }
    }


     //to display the matrix 
     printf("\nMatrix is : ");
     for(i=0;i<n;i++){
       printf("\n");
       for(j=0;j<n;j++){
          printf(" %d",arr[i][j]);
       }
     }


      k=0;

      //to add corresponding rows and column elements 

      while(k<n){

       sum=0;   
       for(i=0;i<n;i++){
         sum=sum+arr[k][i]; 
       }

       for(i=0;i<n;i++){
         sum=sum+arr[i][k]; 
       }

       //to print the result 
       printf("\nFor row and column number %d  sum is %d",k,sum);

       k++;

      }
}

4

solved adjacency matrix sum of corresponding rows and columns [closed]