google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 Write a Program to Sum of Two Matrix in C

Write a Program to Sum of Two Matrix in C

2


Write a Program to Sum of Two Matrix in C


#include <stdio.h>
#include <conio.h>

void main()
{
    int r, c, a[100][100], b[100][100], sum[100][100], i, j;

    printf("Enter number of rows (between 1 and 100): ");
    scanf("%d", &r);
    printf("Enter number of columns (between 1 and 100): ");
    scanf("%d", &c);

    printf("\nEnter elements of 1st matrix:\n");

    for(i=0; i<r; ++i)
    {
        for(j=0; j<c; ++j)
        {
            printf("Enter element a%d%d: ",i+1,j+1);
            scanf("%d",&a[i][j]);
        }
     }

    printf("Enter elements of 2nd matrix:\n");

    for(i=0; i<r; ++i)
     {
        for(j=0; j<c; ++j)
        {
            printf("Enter element a%d%d: ",i+1, j+1);
            scanf("%d", &b[i][j]);
        }
     }

    // Adding Two matrices

    for(i=0;i<r;++i)
    {
        for(j=0;j<c;++j)
        {
            sum[i][j]=a[i][j]+b[i][j];
        }
     }

    // Displaying the result
    printf("\nSum of two matrix is: \n\n");

    for(i=0;i<r;++i)
    {
        for(j=0;j<c;++j)
        {

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

            if(j==c-1)
            {
                printf("\n\n");
            }
        }
      }
    
    getch();
}




Output of the Program


Enter number of rows (between 1 and 100): 2
Enter number of columns (between 1 and 100): 3

Enter elements of 1st matrix:
Enter element a11: 2
Enter element a12: 3
Enter element a13: 4
Enter element a21: 5
Enter element a22: 2
Enter element a23: 3
Enter elements of 2nd matrix:
Enter element a11: -4
Enter element a12: 5
Enter element a13: 3
Enter element a21: 5
Enter element a22: 6
Enter element a23: 3

Sum of two matrix is: 

-2   8   7   


10   8   6 




 

Post a Comment

2 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top