Q:

Write a C# Sharp program to check if the number of 3's is greater than the number of 5's

0

Write a C# Sharp program to check if the number of 3's is greater than the number of 5's

Sample Output:

True
False
False

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
namespace exercises
{
   class Program
    {       
        static void Main(string[] args)
        {               
         Console.WriteLine(test(new[] { 1, 5, 6, 9, 3, 3 })); 
         Console.WriteLine(test(new[] { 1, 5, 5, 5, 10, 17 })); 
         Console.WriteLine(test(new[] { 1, 3, 3, 5, 5, 5})); 
        }           
       static bool test(int[] nums)
         {
             int no_3 = 0, no_5 = 0;

            for (int i = 0; i < nums.Length; i++)
            {
                if (nums[i] == 3) no_3++;
                if (nums[i] == 5) no_5++;
            }

            return no_3 > no_5;
         }    
   } 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now