C Online Compiler
Example: Two-Player Time Comparison in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Two-Player Time Comparison #include <stdio.h> int main() { float player1Time, player2Time; // Step 1: Prompt and read time for Player 1 printf("Enter Player 1's time (in seconds): "); scanf("%f", &player1Time); // Step 2: Prompt and read time for Player 2 printf("Enter Player 2's time (in seconds): "); scanf("%f", &player2Time); // Step 3: Compare times to determine the winner if (player1Time < player2Time) { printf("Player 1 wins with a time of %.2f seconds!\n", player1Time); } else if (player2Time < player1Time) { printf("Player 2 wins with a time of %.2f seconds!\n", player2Time); } else { printf("It's a tie! Both players finished in %.2f seconds.\n", player1Time); } return 0; }
Output
Clear
ADVERTISEMENTS