Advertisement
Guest User

what's wrong in this program

a guest
Oct 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int x[5][5],y[5][5],z[5][5],r1,c1,r2,c2,i,j;
  6.     printf("\nenter the size of matrix");
  7.     scanf("%d%d",&r1,&c1);
  8.       printf("\nenter the size of 2nd matrix");
  9.     scanf("%d%d",&r2,&c2);
  10.     if(r1!=r2||c1!=c2)
  11.     {
  12.         printf("\nmatrix addition is not possible");
  13.        
  14.     }
  15.     else
  16.     {
  17.         printf("\nenter%d*%dmatrix",r1,c1);
  18.        
  19.     }
  20.     for(i=0;i<r1;i++)
  21.     {
  22.         for(j=0;i<c1;j++)
  23.         {
  24.             scanf("%d",&x[i][j]);
  25.         }
  26.     }
  27.     printf("\nenter%d*%dmatrix",r2,c2);
  28.     for(i=0;i<r2;i++)
  29.     {
  30.      for(j=0;j<c2;j++)
  31.         {
  32.             scanf("%d",&y[i][j]);
  33.         }
  34.     }
  35.     for(i=0;i<r1;i++)
  36.     {
  37.         for(j=0;j<c2;j++)
  38.         {
  39.             z[i][j]=x[i][j]+y[i][j];
  40.         }
  41.     }
  42.     printf("\naddition of two matrices is ");
  43.     for(i=0;i<r1;i++)
  44.     {
  45.         for(j=0;j<c1;j++)
  46.         {
  47.             printf("%d\t",z[i][j]);
  48.         }
  49.         printf("\n");
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement