Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* C programme to add 2 mattrixs using function */
- #include<stdio.h>
- int r1,c1,r2,c2;
- void madd(int x[r1][c1],int y[r2][c2]);
- int main(void)
- {
- scanf("%d %d %d %d",&r1,&c1,&r2,&c2);
- int a[r1][c1];
- int b[r2][c2];
- int m,n;
- for(m=0;m<r1;m++)
- {
- for(n=0;n<c1;n++)
- {
- printf("enter element a[%d][%d]:\n",m,n);
- scanf("%d",&a[r1][c1]);
- printf("enter element b[%d][%d]:\n",m,n);
- scanf("%d",&b[r1][c1]);
- }
- }
- if((r1==r2)&&(c1==c2))
- {
- madd(a,b);
- }
- else if((r1!=r2)||(c1!=c2))
- {
- printf("addition is not possible\n");
- }
- return 0;
- }
- void madd(int x[r1][c1],int y[r2][c2])
- {
- int z[r1][c1];
- int i,j;
- for(i=0;i<r1;i++)
- {
- for(j=0;j<c1;j++)
- {
- z[r1][c1]=x[r1][c1]+y[r1][c1];
- printf("%d\t",z[r1][c1]);
- }
- }
- }
Add Comment
Please, Sign In to add comment