20_10

Write a C code which computes and prints the sum of each rows of a 2D Matrix.

 Source code:

//Write a C code which computes and prints the sum of each rows of a 2D Matrix. 

#include <stdio.h>

int main()

{

    int matrix[10][10];

    int i,j,r,c; 

    int sum[10]; /* Sum of each row is kept in this array */

printf("Enter the number of row:\n");

    scanf("%d",&r); /* Input no. of rows */

printf("Enter the number of column:\n");

    scanf("%d",&c); /* Input no. of columns */

printf("Enter the matrix:\n");

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

    {

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

        {

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

        }

    }

    /*sum of all rows*/

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

    {

    sum[i]=0;

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

        {

            sum[i] = sum[i] +  matrix[i][j];

        }

    }

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

printf("%d\n",sum[i]);

return 0;

}

Output:

C code which computes and prints the sum of each rows of a 2D Matrix


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...