Plus Minus

  • + 0 comments
    public static void plusMinus(List<int> arr)
        {
            int n = arr.Count;
            if (n > 0 && n <= 100)
            {
                int positives = arr.Count(x => x > 0);
                int negatives = arr.Count(x => x < 0);
                int zeros = arr.Count(x => x == 0);
                
                // Calculate and print ratios with 6 decimal places
                Console.WriteLine("{0:F6}", (decimal)positives / n);
                Console.WriteLine("{0:F6}", (decimal)negatives / n);
                Console.WriteLine("{0:F6}", (decimal)zeros / n);
            }
        }