C program to calculate the subtraction of two matrices using a two-dimensional array

 

C program

C PROGRAM

 C program to calculate the subtraction of two matrices using a two-dimensional array

#include <stdio.h>
#include<conio.h>
void main()
{
  int a[10][10],b[10][10],c[10][10],i,j,rows,columns;
  clrscr();
  printf("enter the number of rows \n");
  scanf("%d",&rows);
  printf("enter the number of columns \n");
  scanf("%d",&columns);
  printf("enter the elements of the first matrix \n");
  for(i=0;i<rows;i++)
  {
    for(j=0;j<columns;j++)
    {
      scanf("%d",&a[i][j]);
      }
      }
      printf("enter the elements of the second matrix \n");
      for(i=0;i<rows;i++)
      {
        for(j=0;j<columns;j++)
        {
          scanf("%d",&b[i][j]);
          }
          }
          printf("subtraction of the two matrix \n");
          {
            for(i=0;i<rows;i++)
            {
              for(j=0;j<columns;j++)
              {
                c[i][j]=a[i][j]-b[i][j];
                printf("%d \n",c[i][j]);
           }
         }
      }
           getch();

     }

OUTPUT :

enter the number of rows 
2
enter the number of columns 
2
enter the elements of the first matrix 
1 1 
1  1
enter the elements of the second matrix 
 2 2 
2 2 
subtraction of the two matrix 
-1 
-1 
-1 
-1 
Process finished.



No comments:

Post a Comment




Copyright Ⓒ 2022 | Mechpedia | All Right Reserved.