C# Tutorial
This C# program is used to find the number of even and odd nummbers in array elements.
for loop and modulus operator to find the number of odd and even elements and displays the number of even and odd numbers using WriteLine method in Console class of System namespace..
/* This C# program to display even and odd numbers count in array. */ using System; // System is a namespace public class Numbers { // Main method which starts the program execution. public static void Main() { int[] numbers = { 10, 7, 25, 40, 93, 22, 45, 52, 85 }; int evenCount, oddCount; evenCount = oddCount = 0; for(int i=0; i < numbers.Length; i++) { if(numbers[i]%2==0) { evenCount++; } else { oddCount++; } } Console.WriteLine("Finds Number of Even and Odd Numbers in Array"); for(int i = 0; i < numbers.Length; i++) { Console.Write(numbers[i]+"\t"); } Console.WriteLine(); Console.WriteLine("Even Numbers Count: " + evenCount); Console.WriteLine("Odd Numbers Count: " + oddCount); Console.ReadKey(); } }
Output:,/p>
C:> csc Numbers.cs C:> Numbers Finds Number of Even and Odd Numbers in Array 10 7 25 40 93 22 45 52 85 Even Numbers Count: 4 Odd Numbers Count: 5
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page