Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define COL 20
void readinput(int (*x)[COL],int,int);//function prototypes
void computesum(int (*x)[COL],int (*y)[COL],int (*z)[COL],int,int);
void printout(int (*x)[COL],int,int);
int main()
{
int row,nor,noc;//nor=no of rows noc=no of columns
int (*a)[COL],(*b)[COL],(*c)[COL];//THIS STATEMENT DECLARES THAT a,b,c are pointers to dimensional arrays
printf("\nHOW MANY ROWS? ");
scanf("%d",&nor);
printf("\nHOW MANY COLUMNS? ");
scanf("%d",&noc);
for(row=0;row<nor;row++)
{
(*a)[row]=(int *) malloc (noc * sizeof(int));//dynamic memory allocation for arrays a,b,c
(*b)[row]=(int *) malloc (noc * sizeof(int));
(*c)[row]=(int *) malloc (noc * sizeof(int));
}
printf("\nREAD INPUT OF FIRST TABLE:\n");
readinput(a,nor,noc);//inputting first table(function call)
printf("\nREAD INPUT OF SECOND TABLE:");
readinput(b,nor,noc);//inputting second table(function call)
computesum(a,b,c,nor,noc);//computing the sum of the tables(function call)
printf("\nPRINTING OUTPUT\n");
printout(c,nor,noc);//showing the result(function call)
getch();
return 0;
}
void readinput(int (*x)[COL],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",*(x+i)+j);//reading each element of the table
}
}
return;
}
void computesum(int (*x)[COL],int (*y)[COL],int (*z)[COL],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
*(*(z+i)+j) = *(*(x+i)+j) + *(*(y+i)+j);//adding corresponding elements
}
}
}
void printout(int (*x)[COL],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%-5d",*(*(x+i)+j));//printing out the numbers
if(j==c-1)
printf("\n");
}
}
}
Please post reply if you can.......thanks