In: Computer Science
Write a C program that allows users to enter three runners name (up to 20 characters) and their runtime (2 decimals)
(1) First and Last name
(2) Running time for 100 m ex. 9.96 seconds
your program should rank them in ascending order of their runtime. example:
usian Bolt - 9.96 sec - First Place
John doe - 9.99 sec - second Place
Pete Urel -10.11 sec - third place
BUT they fan tie for first place and no second place awarded
usian Bolt - 9.96 sec - First Place
John doe - 9.96 sec -First Place
Pete Urel -10.11 sec - third place
OR they can tie for second place and no third place awarded
usian Bolt - 9.96 sec - First Place
John doe - 10.11sec - second Place
Pete Urel -10.11 sec - second place
YOU CANNOT USE AN ARRAY DATA STRUCTURE TO STORE DATA FOR EACH RUNNER
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char
fname1[20],fname2[20],fname3[20],lname1[20],lname2[20],lname3[20];
float time1,time2,time3;
int first,second,third;
clrscr();
printf("\n enter the first and last name of first runner and
running time ");
scanf("%s%s%f",fname1,lname1,&time1);
fflush(stdin);
printf("\n enter the first and last name of second runner and
running time ");
scanf("%s%s%f",fname2,lname2,&time2);
fflush(stdin);
printf("\n enter the first and last name of third runner and
running time ");
scanf("%s%s%f",fname3,lname3,&time3);
fflush(stdin);
if(time1>time2&&time1>time3&&time2!=time3)
{
first=time1;
printf("%s %s %0.2f sec - First Place",fname1,lname1,time1);
if(time2>time3)
{
second=time2;
printf("\n %s %s %0.2fsec - Second
Place",fname2,lname2,time2);
third=time3;
printf("\n %s %s %0.2fsec - Thirs
Place",fname3,lname3,time3);
}
else
{
second=time3;
printf("\n %s %s %0.2f sec - Second
Place",fname3,lname3,time3);
third=time1;
printf("\n %s %s %0.2f sec - Third
Place",fname2,lname2,time2);
}
}
else
if(time2>time3&&time2>time1&&time3!=time1)
{
first=time2;
printf("\n %s %s %0.2f sec - First
Place",fname2,lname2,time2);
if(time3>time1)
{
second=time3;
printf("\n %s %s %0.2f sec - Second
Place",fname3,lname3,time3);
third=time1;
printf("\n %s %s %0.2f sec - Third
Place",fname1,lname1,time1);
}
else
{
second=time1;
printf("\n %s %s %0.2f sec - Second
Place",fname1,lname1,time1);
third=time3;
printf("\n %s %s %0.2f sec - Third
Place",fname3,lname3,time3);
}
}
else
if(time3>time1&&time3>time2&&time1!=time2)
{
first=time3;
printf("\n %s %s %0.2f sec - First
Place",fname3,lname3,time3);
if(time1>time2)
{
second=time1;
printf("\n %s %s %0.2f sec - Second
Place",fname1,lname1,time1);
third=time2;
printf("\n %s %s %0.2f sec - Third
Place",fname2,lname2,time2);
}
else
{
second=time2;
printf("\n %s %s %0.2f sec - Second
Place",fname2,lname2,time2);
third=time1;
printf("\n %s %s %0.2f sec - Third
Place",fname1,lname1,time1);
}
}
else if(time1==time2)
{
if(time1<time3)
{
printf("\n %s %s %0.2f sec - First
Place",fname1,lname1,time1);
printf("\n %s %s %0.2f sec - First
Place",fname2,lname2,time2);
printf("\n %s %s %0.2f sec = Third
Place",fname3,lname3,time3);
}
else
{
printf("\n %s %s %0.2f sec - First
Place",fname3,lname3,time3);
printf("\n %s %s %0.2f sec - Second
Place",fname1,lname1,time1);
printf("\n %s %s %0.2f sec = Second
Place",fname2,lname2,time2);
}
}
else if(time2==time3)
{
if(time2<time1)
{
printf("\n %s %s %0.2f sec - First
Place",fname2,lname2,time2);
printf("\n %s %s %0.2f sec - Frist
Place",fname3,lname3,time3);
printf("\n %s %s %0.2f sec - Third
place",fname1,lname1,time1);
}
else
{
printf("\n %s %s %0.2f sec - First
Place",fname1,lname1,time1);
printf("\n %s %s %0.2f sec - Second
Place",fname2,lname2,time2);
printf("\n %s %s %0.2f sec - Second
Place",fname3,lname3,time3);
}
}
else
{
if(time3<time2)
{
printf("\n %s %s %f sec - First Place",fname1,lname1,time1);
printf("\n %s %s %f sec - First Place",fname3,lname3,time3);
printf("\n %s %s %f sec - Third Place",fname2,lname2,time2);
}
else
{
printf("\n %s %s %f sec - First Place",fname2,lname2,time2);
printf("\n %s %s %f sec - Second Place",fname1,lname1,time1);
printf("\n %s %s %f sec - Second Place",fname3,lname3,time3);
}
}
}
Sample Run1:
Sample Run2:
Sample Run3: