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, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors and Social Networking. Feel Free to let me know any of your concerns about hacking or let me know if you need any more methods on hacking anything. Enjoy Learning

No comments:

Post a Comment