Here is the code building a table of contents which i felt correct from every sense but output is somewhat unsatisfactory.
#include<stdio.h>
#include<limits.h>
#include<stdlib.h>
int**buildtable(void);
void filltable(int**table);
void processtable(int**table);
int smaller(int first,int second);
int larger(int first,int second);
int rowMinimum(int*rowPtr);
int rowMaximum (int*rowPtr);
float rowAvg(int*rowPtr);
int main()
{int**table;
table=buildtable();
filltable(table);
processtable(table);
return 0;
}
int**buildtable()
{int rowNum;
int colNum;
int**table;
int row;
printf("\nEnter the number of rows in the table:");
scanf("%d",&rowNum);
table=(int**) calloc(rowNum+1,sizeof(int*));
for(row=0;row<rowNum;row++)
{printf("Enter the no of integer in row%d",row+1);
scanf("%d",&colNum);
table[row]=(int*)calloc(colNum+1,sizeof(int));
table[row][0]=colNum;
}
table[row]=NULL;
return table;
}
void filltable(int**table)
{
int row=0;
int column;
printf("\nNow we fill the table\n");
printf("\nFor each row enter the data");
printf("\nand press return:");
while(table[row]!=NULL)
{
printf("\n row %d(%d integers)===>",row+1,table[row][0]);
for ( column=1;column<=*table[row];column++);//goto OUTPUT PROBLEM
scanf("%d",table[row]+column);
row++;
}return;
}
void processtable(int** table)
{int row =0,rowMax,rowMin;
float ravg;
while(table[row]!=NULL)
{rowMin=rowMinimum(table[row]);
rowMax=rowMaximum(table[row]);
ravg=rowAvg(table[row]);
printf("\nThe statistics for row%d",row+1);
printf("\nThe minimum:%5d",rowMin);
printf("\nThe maximum:%5d",rowMax);
printf("\nThe avg.:%8.2f",ravg);
row++;
}
}
int rowMinimum (int*rowPtr)
{int rowMin =INT_MAX,column;
printf("\nINT_MAX:",rowMin);
for(column=1;column<=*rowPtr;column++)
{
rowMin=smaller(rowMin,*(rowPtr+column));
}return rowMin;
}
int rowMaximum(int*rowPtr)
{int rowMax=INT_MIN,column;
printf("\nINT_MIN:",rowMax);
for(column=1;column<=*rowPtr;column++)
rowMax=larger(rowMax,*(rowPtr+column));
return rowMax;
}
float rowAvg(int*rowPtr)
{float total=0;
float ravg; int column;
for(column=1;column<=*rowPtr;column++)
total+=(float)*(rowPtr+column);
ravg=total/ *rowPtr;
return ravg;
}
int smaller(int first,int second)
{return(first<second ? first:second);
}
int larger (int first,int second)
{return(first>second?first:second);
}
OUTPUT PROBLEM:
Here Minimum ,Maximum and Average Value are all zero.
Also where i commented in the code as "goto" here scanf() should take inputs according to the user but it is taking only one input per row.