Discussion Forums

New User? Please read instructions!

C program for matrix addition  

  RSS

thiyagarajan.s
Active Member
Joined: 4 months  ago
Posts: 14
27/01/2017 10:05 am  

C program for matrix addition


ReplyQuote
prakash
Eminent Member
Joined: 4 months  ago
Posts: 20
17/02/2017 5:34 am  

Hi,

C program for matrix addition is given below.

 

#include <stdio.h>

int main()

{

    int a, b, c, d;

    int m1[10][10], m2[10][10], sum[10][10];

 

    printf("Please enter the number of rows of matrix\n");

    scanf("%d", &a);

    printf("Please enter number of columns of matrix\n");

    scanf("%d", &b);

    printf("Please enter the elements of first matrix one by one\n");

 

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

    {

          for ( d = 0 ; d < b ; d++ )

          {

                scanf("%d", &m1[c][d]);

          }

    }

    printf("Please enter the elements of second matrix one by one\n");

 

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

    {

          for ( d = 0 ; d < b ; d++ )

          {

                scanf("%d", &m2[c][d]);

          }

    }

 

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

    {

          for ( d = 0 ; d < b ; d++ )

          {    

               sum[c][d] = m1[c][d] + m2[c][d];

          }

    }

 

    printf("The sum of entered matrices is below:\n");

 

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

    {

         for ( d = 0 ; d < b ; d++ )

         printf("%d\t", sum[c][d]);

 

         printf("\n");

    }

    return 0;

}

 

Output:

Please enter the number of rows of matrix

2

Please enter number of columns of matrix

2

Please enter the elements of first matrix one by one

3

3

3

3

Please enter the elements of second matrix one by one

4

4

4

4

The sum of entered matrices is below:

7    7

7    7

 

Edited: 3 months  ago

ReplyQuote
  
Working

Please Login or Register

Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin

Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!