Skip to main content

C program to read m x n matrix and calculate the Row sum and Column sum of the matrix.

 C program to read m x n matrix and calculate the Row sum and Column sum of the matrix.

    In this example, we read a m x n matrix whose value would be entered by the user then the sum of row and column is calculated. Here in the example we have taken a matrix of order 3 x 2 whose row sum and column sum is displayed in the output screen.

PROGRAM TO READ m x n MATRIX AND CALCULATE THE ROW SUM AND COLUMN SUM OF THE MATRIX:

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,m[100][100],row,column,rsum,csum=0;
    printf("Enter the row size of the matrix :");
    scanf("%d",&row);
    printf("Enter the column size of the matrix :");
    scanf("%d",&column);
    printf("Enter the Matrix : ");
    for(i=0;i<row;i++)
    {
        for(j=0;j<column;j++)
        {
            scanf("%d",&m[i][j]);
        }
    }
    for(i=0;i<row;i++)
    {
        rsum=0;
        for(j=0;j<column;j++)
        {
            rsum=rsum+m[i][j];
        }
        printf("\nSum of row %d : %d",i+1,rsum);
    }
    for(j=0;j<column;j++)
    {
        csum=0;
        for(i=0;i<row;i++)
        {
            csum=csum+m[i][j];
        }
        printf("\nSum of column %d : %d",j+1,csum);
    }
    getch();
}


OUTPUT  TO READ M X N MATRIX AND CALCULATE THE ROW SUM AND COLUMN SUM OF THE MATRIX:

    Enter the row size of the matrix :3

    Enter the column size of the matrix :2

    Enter the Matrix : 12

    34

    65

    7

    23

    9

    

    Sum of row 1 : 46    

    Sum of row 2 : 72    

    Sum of row 3 : 32    

    Sum of column 1 : 100

    Sum of column 2 : 50 


NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn together. 


MOTTO: 

                    You Learn, I Learn together We Learn.

Comments

Popular posts from this blog

C Program to print the PASCAL Triangle up to the Nth row where n is a value inputted by the user

 C Program to print the PASCAL Triangle up to the Nth row where n is a value inputted by the user.  .    In this example, we will print a Pascal's triangle upto to the value of the Nth row entered by the user. In the output section we have taken the value of n as 6 and the pascal's triangle is shown in the output. No, it is not that you have to take the value of n as 6, you can enter any value according to your choice. And the required pascal's tringle will be available on the screen.   What is Pascal's Triangle? Pascal's Triangle is a triangular arrangement of the binaomaial coefficients of the expansion (x+y) n  for positive integral values of n. PROGRAM  TO PRINT THE PASCAL TRIANGLE UP TO THE N-TH ROW WHERE N IS A VALUE INPUTTED BY THE USER: #include <stdio.h> #include <conio.h> void  main() {      int  n,coef=1,space,i,j;     printf( "Enter the value of n:" ); ...

C Program To Swap Two Numbers Without Using/Using Third Variable

  C PROGRAM TO SWAP TWO NUMBERS.   In this example, we will learn how to swap two numbers using third variable.   FLOWCHART TO SWAP TWO NUMBERS:         PROGRAM:   #include <stdio.h> int   main () {      int   a , b , c ;      printf ( "Enter the value of a : " );      scanf ( "%d" ,& a );      printf ( "Enter the value of b : " );      scanf ( "%d" ,& b );      printf ( " \n Before swapping values of a=%d and b=%d" , a , b );      c = a ;      a = b ;      b = c ;      printf ( " \n After swapping values of a=%d and b=%d" , a , b ); }   OUTPUT:     C PROGRAM TO S...

C Program to Check a Whether a Number is Divisible by 5 or Not

 C Program to Check a Whether a Number is Divisible by 5 or Not            In this program we will check a number entered by the user will be divisible by 5 or Not. We have solved this problem using if-else statement. Program: #include <stdio.h> #include <conio.h> int  main() {      int  x;     printf( "Enter a number" );     scanf( "%d" ,&x);      if (x% 5 == 0 )         printf( "The number %d is divisible by 5" ,x);      else         printf( "The number %d is not divisible by 5" ,x);      return   0 ; } Output: NOTE:   You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn toget...

C program to convert a given temperature value from Fahrenheit to Centigrade and vice versa?

  Write a C program to convert a given temperature value from Fahrenheit to Centigrade and vice versa?          In this example we will learn how to convert a given temperature in Fahrenheit to Centigrade and to convert given  temperature value from Centigrade to Fahrenheit depending on the choice of the user.                To solve this program we should have basic knowledge in c and most importantly a clear concept on : Switch Statement             And we must know the formula of conversion from Fahrenheit to Centigrade(Celsius) and Centigrade(Celsius) to Fahrenheit. Fahrenheit To Centigrade Centigrade To Fahrenheit PROGRAM       #include <stdio.h> #include <conio.h> void   main () {      float   f , c ;      int   ch ;      printf ( "...

C Program to determine the Range and Average of the values entered by the user(to terminate enter -1).

C Program to determine the Range and Average of the values entered by the user(to terminate enter -1).     This is a program to calculate the range and average of the values entered by the user and to terminate it by entering -1 and it will determine the highest-value, lowest-value, range, average and also it will count the number of values entered by the user. PROGRAM: #include <stdio.h> #include <math.h> int   main () {      int   count = 0 ;      float   value , high , low , average , range , sum = 0 ;      printf ( "Enter the values (to terminate enter -1) : \n " );      while ( 1 )     {          scanf ( "%f" ,& value );          if ( value !=- 1 )         {      ...