C Program For Passing Array to Function (Matrix addition)

#include<stdio.h>
#include<conio.h>

void add( int a[][], int b[][],int r1,int r2, int c1, int c2);
void main()
{
int a[5][5],b[5][5];
int r1,r2,c1,c2,i,j;
clrscr();
printf("r1 r2 c1 c2");
scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
if(r1!=r2||c1!=c2)
{
printf("Not Possible");
getch();
exit(0);
}
printf("first matrix elements:");
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);

 printf("first matrix elements:");
 for(i=0;i<r1;i++)
 for(j=0;j<c1;j++)
 scanf("%d",&a[i][j]);
 add(a,b,r1,c1,r2,c2);
 getch();
}
     void add(int a[][], int b[][],int r1, int c1, int r2, int c2)
     {
    int c[10][10];
   for(i=0;i<r1;i++)
   for(j=0;j<c1;j++)
   c[i][j]=a[i][j]+b[i][j];


    printf("resultant matrix is: \n");
    for(i=0;i<r1;i++)
    for(j=0;j<c1;j++)
    printf("%d",a[i][j]);
    }
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment