C program to perform subtraction of two matrices

C program to perform subtraction of two matrices 


 /*******************************************

 C program to perform subtraction of two matrices 

 **************************************************/

#include<stdio.h>

#include<conio.h>

void main()

{

    int a[20][20],b[20][20],c[20][20];

    int i, j,n,m;

    printf("How many rows and columns\n");

    scanf("%d%d",&n,&m);

    printf("Enter array elements for first array\n");

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

    {

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

        {

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

        }

    }

     printf("Enter array elements for second array\n");

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

    {

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

        {

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

        }

    }

    printf("\n");

    printf("Following is %d X %d first array\n",n,m);

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

    {

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

        {

            printf("%d\t",a[i][j]);

        }

        printf("\n");

    }

    printf("Following is %d X %d second array\n",n,m);

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

    {

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

        {

            printf("%d\t",b[i][j]);

        }

        printf("\n");

    }

    printf("subtraction of two matrices is\n");

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

    {

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

        {

            c[i][j]=a[i][j]-b[i][j];

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

        }

        printf("\n");

    }

    printf("End of program");

    getch();

}


How many rows and columns

2

2

Enter array elements for first array

4

5

8

9

Enter array elements for second array

2

3

7

8


Following is 2 X 2 first array

4 5

8 9

Following is 2 X 2 second array

2 3

7 8

Addition of two matrices is

2 2

1 1

End of program


टिप्पणी पोस्ट करा

0 टिप्पण्या