Commit c0a1d3ef by ilahma

Update homework2.c

parent 78824be2
Showing with 96 additions and 0 deletions
#include <stdio.h>
#include <string.h>
void readdata(char name[15][15],float points[15], int n);
void printdata(char name[15][15],float points[15], int n);
void comparedata(char name[15][15],float points[15],int n);
int main ()
{
char names[15][15];
float points[15];
float temp;
int n;
int i;
int j;
printf("Please enter the number of photographers ( The value should be less than 15)\n");
scanf("%d",&n);
while(n<0 || n>15)
{
printf("PLEASE ADD NUMBER BETWEEN 1 AND 15\n\n");
scanf("%d",&n);
}
readdata(names,points,n);
printdata(names,points,n);
comparedata(names,points,n);
printf("Top 3:\n");
for(i=0;i<3;i++)
{
printf("No%d: %s %.2f\n",i+1, names[i],points[i]);
}
if(points[i]==0)
{
printf("Disqualified one(s): %s %.f \n", names[i],points[i]);
}
else
{
printf("Disqualified: none");
}
return 0;
}
void readdata(char name[15][15],float points[15],int n)
{
int i;
for(i=0; i<n;i++)
{
scanf("%s%f", name[i],&points[i]);
}
}
void printdata(char name[15][15],float points[15],int n)
{
int i;
for(i=0; i<n;i++)
{
printf("%s\t", name[i]);
printf("%.f\n", points[i]);
}
}
void comparedata(char name[15][15],float points[15],int n)
{
int i;
int j;
float temp;
for(i=0; i<n;i++)
{
for (j = 0; j < (n - i - 1); j++)
{
if (points[j] < points[j + 1])
{
temp = points[j];
points[j] = points[j + 1];
points[j + 1] = temp;
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment