Write a program to determine the winner of a tournament and calculate the total number of matches required to identify the winner?
Loading
Write a program to determine the winner of a tournament and calculate the total number of matches required to identify the winner?
using System;
class Tournament
{
public static void Main()
{
int totalTeams = 128; // Initial number of teams
int totalMatches = totalTeams - 1; // Number of matches = teams - 1
Console.WriteLine("Total matches played in the tournament: " + totalMatches);// Simulate the roundsint round = 1;int teamsInCurrentRound = totalTeams;while (teamsInCurrentRound > 1){int matchesInCurrentRound = teamsInCurrentRound / 2;Console.WriteLine($"Round {round}: {matchesInCurrentRound} matches");// Half of the teams are eliminated in each roundteamsInCurrentRound /= 2;round++;}}
}
Example Output:
Total matches played in the tournament: 127
Round 1: 64 matches
Round 2: 32 matches
Round 3: 16 matches
Round 4: 8 matches
Round 5: 4 matches
Round 6: 2 matches
Round 7: 1 matches