Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace EvenOddElementZeroCountInArray
  8. {
  9.     class EvenOddElementZeroCountInArray
  10.     {
  11.         static int[] FillArray(int n)
  12.         {
  13.             int[] array = new int[n];
  14.             for (int i = 0; i < array.Length; i++)
  15.             {
  16.                 array[i] = int.Parse(Console.ReadLine());
  17.             }
  18.             Console.WriteLine();
  19.             return array;
  20.         }
  21.         static void PrintArray(int[] array)
  22.         {
  23.             for (int i = 0; i < array.Length; i++)
  24.             {
  25.                 Console.Write(array[i] + " ");
  26.             }
  27.         }
  28.         static void EvenElementsInArray(int[] array)
  29.         {
  30.             for (int i = 0; i < array.Length; i++)
  31.             {
  32.                 if (array[i] != 0 && array[i] % 2 == 0)
  33.                 {
  34.                     Console.Write(array[i] + " ");
  35.                 }
  36.             }
  37.         }
  38.         static void OddElementsInArray(int[] array)
  39.         {
  40.             for (int i = 0; i < array.Length; i++)
  41.             {
  42.                 if (array[i] % 2 == 1)
  43.                 {
  44.                     Console.Write(array[i] + " ");
  45.                 }
  46.             }
  47.         }
  48.         static int ZeroCounter(int[] array)
  49.         {
  50.             int counter = 0;
  51.             for (int i = 0; i < array.Length; i++)
  52.             {
  53.                 if (array[i] == 0)
  54.                 {
  55.                     counter++;
  56.                 }
  57.             }
  58.             return counter;
  59.         }
  60.         static string GetZeroPositions(int[] array)
  61.         {
  62.             string result = "";
  63.             for (int i = 0; i < array.Length; i++)
  64.             {
  65.                 if (array[i] == 0)
  66.                 {
  67.                     result += (i + 1) + " ";
  68.                 }
  69.             }
  70.             return result;
  71.         }
  72.         static void Main(string[] args)
  73.         {
  74.             Console.Write("Enter array`s lenght: ");
  75.             int n = int.Parse(Console.ReadLine());
  76.             int[] numbers = FillArray(n);
  77.  
  78.             Console.WriteLine("Array`s elements:");
  79.             PrintArray(numbers);
  80.             Console.WriteLine();
  81.  
  82.             Console.Write("Even: ");
  83.             EvenElementsInArray(numbers);
  84.             Console.WriteLine();
  85.  
  86.             Console.Write("Odd: ");
  87.             OddElementsInArray(numbers);
  88.             Console.WriteLine();
  89.  
  90.             int zeroCounter = ZeroCounter(numbers);
  91.             Console.Write("Zero counts: " + zeroCounter);
  92.             Console.WriteLine();
  93.  
  94.             string result = GetZeroPositions(numbers);
  95.             Console.Write("Zero positions in the array: " + result);
  96.  
  97.             Console.ReadKey(true);
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement