Q:

Write a C# Sharp program to count even number of elements in a given array of integers

0

Write a C# Sharp program to count even number of elements in a given array of integers

Sample Output:

2

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, 7, 9, 10, 12 })); 
        }           
       static int test(int[] nums)
          {
            int evens = 0;

            for (int i = 0; i < nums.Length; i++)
            {
                if (nums[i] % 2 == 0) evens++;
            }
            return evens;
          }    
   }
}

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