mardi 3 octobre 2023

Calculate the total number of chess pairs among n players

 Calculate the total number of chess pairs among n players


class Solution

{

    /// Counts the number of pairs for n​​​​​​‌​‌​​‌‌​​​‌‌‌​‌​‌‌​​​​‌​​ players.

    public static int Count(int n)

    {

        if(n< 2 || n > 10000){

            throw new ArgumentException("invalid input!");

        }

        double toReturn = n * (n-1) /2 ;

        return (int)toReturn; 

    }


    

}

Aucun commentaire:

Enregistrer un commentaire