#include <stdio.h>
#include <math.h>
void datain(int,int,float[10000][4]);
void prtable(int,int,float[10000][4]);
void sortdata(int,int,float[10000][4]);
void main ()
{
/*Author:GSD
Date:09.11.2001
Assignment 2:
Modifications: None
Version 1.0*/
int n,m;
float a[10000][4];
a[0][0]=0.0;
n=4;
printf("Please enter the number of persons in the table\n\r");
scanf("%d",&m);
/*Create table and input data*/
datain(n,m,a);
/*print out the table unsorted*/
prtable(n,m,a);
/*sort date
sortdata(n,m,a)*/
}
void datain(int n,int m,float a[10000][4])
{
/*Author: GSD
Date:09.11.2001
Assignment 2:
Modifications: None
Version 1.0
Function: Fixing the size of the two dimensional array and input the data*/
int i,j;
for (j=1;j<=n;j++)
{
for (i=1;i<=m;i++)
{
if (j==1) printf("\n\rPlease enter Person Id of person %3d ",i);
if (j==2) printf("\n\rPlease enter the value of wage of person %3d ",i);
if (j==3) printf("\n\rPlease enter the sex ((0) male (1) female) of person %3d ",i);
if (j==4) printf("\n\rPlease enter the age of person %3d ",i);
scanf("%f",&a[i][j]);
}
}
return;
}
void prtable(int n,int m,float a[10000][4])
{
/*Author: GSD
Date:09.11.2001
Assignment 2:
Modifications: None
Version 1.0
Function: To print out the data unsorted*/
int i,j;
printf(" Person ID\tWage\t Sex\t Age\n\r");
for (i=1;i<=m;i++)
{
for (j=1;j<=n;j++)
{
printf("%10.0f",a[i][j]);
}
printf("\n\r");
}
return;
}
void sortdata(int n,int m,float a[10000][4])
{
/*Author: GSD
Date:09.11.2001
Assignment 2:
Modifications: None
Version 1.0
Function:To sort the data*/
int i,j,t;
char type;
t=1;
while (t==1)
{
printf("\n\rHow do you want the data to be sorted ?");
printf("\n\rAscending by Person ID,type a");
printf("\n\rAscending by Wage, type b");
printf("\n\rAscending by Age, type c");
printf("\n\rOnly females, print d");
printf("\n\rOnly males, print e\n\r");
scanf("\n%c",&type);
if (type='a')
{
printf("Person ID\tWage\tSex\tAge");
printf("%10.0f",a[i][j]);
}
else
{
printf("\n\rNot yet working");
}
printf("Do you want to sort the array again? Yes (1) or No (0)");
scanf("%d",&t);
}
return;
}
The sort function does not work any clues