Computer Science, asked by MeghaLakshmiB, 7 months ago

Write a program to input numbers into an array of 4 rows and 4 columns Display the sum of each row
each column in the format given below!
Sample data
1 2 3 4 10
4 3 2 1 10
2 3 1 5 11
6 2 3 5
13 10 9 15
The numbers in BOLD are input by the user. The numbers in italics are the results. Mense de m
numbers to write your program. Input from the user is to be taken

Answers

Answered by pndd11
0

Answer:

vrgybuubybytvt tcyvyb

Answered by ridhimakh1219
0

Write a program to input numbers into an array of 4 rows and 4 columns display the sum of each row  and each column

Explanation:

C Program to find Sum of each row and column of a Matrix

#include <stdio.h>

int main()

{

    int i,j,k,arr1[10][10],rsum[10],csum[10],n;

    printf("Enter the size of the square matrix: ");

    scanf("%d", &n);

    printf("Enter elements in matrix :\n");

      for(i=0;i<n;i++)

       {

           for(j=0;j<n;j++)

           {

           printf("element - [%d],[%d] : ",i,j);

           scanf("%d",&arr1[i][j]);

           }

       }  

   printf("The matrix is :\n");

     for(i=0;i<n;i++)

 {

         for(j=0;j<n ;j++)

             printf("% 4d",arr1[i][j]);

      printf("\n");

 }

    /* Sum of rows */

    for(i=0;i<n;i++)

    {

       rsum[i]=0;

      for(j=0;j<n;j++)

        rsum[i]=rsum[i]+arr1[i][j];

    }

     /* Sum of Column */

     for(i=0;i<n;i++)

     {

  csum[i]=0;

  for(j=0;j<n;j++)

 csum[i]=csum[i]+arr1[j][i];

     }

     printf("The sum of rows and columns of the matrix is :\n");

     for(i=0;i<n;i++)

     {

   for(j=0;j<n;j++)

      printf("% 4d",arr1[i][j]);

   printf("% 8d",rsum[i]);

   printf("\n");

      }

      printf("\n");

    for(j=0;j<n;j++)

            {

        printf("% 4d",csum[j]);

            }

           printf("\n\n");

   return 0;

}

Output

Enter the size of the square matrix: 4              

Enter elements in matrix :                        

element - [0],[0] : 1

element - [1],[1] : 3    

element - [1],[2] : 2  

element - [1],[3] : 1  

element - [2],[0] : 2

element - [2],[1] : 3

element - [2],[2] : 1

element - [2],[3] : 5

element - [3],[0] : 6

element - [3],[1] : 2  

element - [3],[2] : 3    

element - [3],[3] : 5

The matrix is :  

  1   2   3   4            

  4   3   2   1                                

  2   3   1   5                                

  6   2   3   5                                      

The sum of rows and columns of the matrix is :                          

  1   2   3   4      10                                            

  4   3   2   1      10                                                  

  2   3   1   5      11                              

  6   2   3   5      16                  

                                                     

 13  10   9  15        

Similar questions