Advertisement
Aborigenius

CountOfGivenArrayElement

Jun 16th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 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 CountSomeArrayElement
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string N = (Console.ReadLine());
  14.             int counter = 0;
  15.             int[] myArray = N.Split(' ').Select(t => Convert.ToInt32(t)).ToArray();
  16.  
  17.  
  18.  
  19.             //     for (int i = 0; i < myArray.Length; i++)
  20.             //     {
  21.             //         Console.WriteLine("Element[{0}] = {1}", i, myArray[i]);
  22.             //     }
  23.  
  24.             int checkNumber = int.Parse(Console.ReadLine());
  25.  
  26.             foreach (var num in myArray)
  27.             {
  28.                 if (checkNumber == num)
  29.                 {
  30.                     counter++;
  31.                 }
  32.             }
  33.  
  34.             Console.WriteLine(counter);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement