rootUser

Add two mattrixs using function

May 24th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. /* C programme to add 2 mattrixs using function */
  2. #include<stdio.h>
  3.  
  4. int r1,c1,r2,c2;
  5.  
  6. void madd(int x[r1][c1],int y[r2][c2]);
  7.  
  8. int main(void)
  9. {
  10.  
  11.     scanf("%d %d %d %d",&r1,&c1,&r2,&c2);
  12.     int a[r1][c1];
  13.     int b[r2][c2];
  14.  
  15.     int m,n;
  16.  
  17.     for(m=0;m<r1;m++)
  18.     {
  19.         for(n=0;n<c1;n++)
  20.         {
  21.             printf("enter element a[%d][%d]:\n",m,n);
  22.             scanf("%d",&a[r1][c1]);
  23.             printf("enter element b[%d][%d]:\n",m,n);
  24.             scanf("%d",&b[r1][c1]);
  25.         }
  26.     }
  27.  
  28.     if((r1==r2)&&(c1==c2))
  29.     {
  30.         madd(a,b);
  31.     }
  32.  
  33.     else if((r1!=r2)||(c1!=c2))
  34.     {
  35.         printf("addition is not possible\n");
  36.     }
  37.  
  38.     return 0;
  39. }
  40. void madd(int x[r1][c1],int y[r2][c2])
  41. {
  42.     int z[r1][c1];
  43.     int i,j;
  44.     for(i=0;i<r1;i++)
  45.     {
  46.         for(j=0;j<c1;j++)
  47.         {
  48.             z[r1][c1]=x[r1][c1]+y[r1][c1];
  49.             printf("%d\t",z[r1][c1]);
  50.         }
  51.     }
  52. }
Add Comment
Please, Sign In to add comment