Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EvenOddElementZeroCountInArray
- {
- class EvenOddElementZeroCountInArray
- {
- static int[] FillArray(int n)
- {
- int[] array = new int[n];
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = int.Parse(Console.ReadLine());
- }
- Console.WriteLine();
- return array;
- }
- static void PrintArray(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- }
- static void EvenElementsInArray(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] != 0 && array[i] % 2 == 0)
- {
- Console.Write(array[i] + " ");
- }
- }
- }
- static void OddElementsInArray(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] % 2 == 1)
- {
- Console.Write(array[i] + " ");
- }
- }
- }
- static int ZeroCounter(int[] array)
- {
- int counter = 0;
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] == 0)
- {
- counter++;
- }
- }
- return counter;
- }
- static string GetZeroPositions(int[] array)
- {
- string result = "";
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] == 0)
- {
- result += (i + 1) + " ";
- }
- }
- return result;
- }
- static void Main(string[] args)
- {
- Console.Write("Enter array`s lenght: ");
- int n = int.Parse(Console.ReadLine());
- int[] numbers = FillArray(n);
- Console.WriteLine("Array`s elements:");
- PrintArray(numbers);
- Console.WriteLine();
- Console.Write("Even: ");
- EvenElementsInArray(numbers);
- Console.WriteLine();
- Console.Write("Odd: ");
- OddElementsInArray(numbers);
- Console.WriteLine();
- int zeroCounter = ZeroCounter(numbers);
- Console.Write("Zero counts: " + zeroCounter);
- Console.WriteLine();
- string result = GetZeroPositions(numbers);
- Console.Write("Zero positions in the array: " + result);
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement