Welcome back,
I am back with the output blog for the program shared recently. If you want to try that program then visit last to last blog on my blog and for the explanation part visit the blog just before this blog.
Let us now look at the program itself.
You can copy the above code below :
#define MAX_RACERS 100
// Function to sort the race times in ascending order using Bubble Sort
void bubbleSort(float times[], int n) {
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (times[j] > times[j + 1]) {
// Swap the elements
float temp = times[j];
times[j] = times[j + 1];
times[j + 1] = temp;
}
}
}
}
int main() {
float raceTimes[MAX_RACERS];
int numRacers = 0;
char option;
// Input race times for existing racers
printf("Enter the number of racers: ");
scanf("%d", &numRacers);
if (numRacers <= 0 || numRacers > MAX_RACERS) {
printf("Invalid number of racers. Please enter a value between 1 and %d.\n", MAX_RACERS);
return 1;
}
printf("Enter race times for %d racers (in seconds):\n", numRacers);
for (int i = 0; i < numRacers; i++) {
printf("Racer %d: ", i + 1);
scanf("%f", &raceTimes[i]);
}
// Sort race times in ascending order
bubbleSort(raceTimes, numRacers);
// Display the sorted race times in top-to-bottom position
printf("\nTop-to-bottom position:\n");
for (int i = 0; i < numRacers; i++) {
printf("Racer %d: %.2f seconds\n", i + 1, raceTimes[i]);
}
// Registration for a new racer
printf("\nDo you want to register a new racer? (Y/N): ");
scanf(" %c", &option);
if (option == 'Y' || option == 'y') {
if (numRacers == MAX_RACERS) {
printf("The maximum number of racers has been reached. Cannot register a new racer.\n");
} else {
printf("Enter the race time for the new racer (in seconds): ");
scanf("%f", &raceTimes[numRacers]);
numRacers++;
// Sort the updated race times with the new racer
bubbleSort(raceTimes, numRacers);
// Display the updated top-to-bottom position
printf("\nUpdated top-to-bottom position:\n");
for (int i = 0; i < numRacers; i++) {
printf("Racer %d: %.2f seconds\n", i + 1, raceTimes[i]);
}
}
} else {
printf("Thank you for using the race time organizer!\n");
}
return 0;
}
Now without wasting anytime let us look at the output of this program.
If you will go through the explanation shared yesteday you will learn easily about this output.
If you also want to learn basics and start your C programming journey then find a teacher today for free on Youtube.
I learnt alot from a teacher who teaches c in hindi and if you are finding someone who teaches in hindi then this person will definitely help you.
I am happy to call myself a trader and small programmer at the same time now.
Happy trading and keep learning what you love.