Find the occurrence of an integer in the array in C#

 Solution 1:

// C# code for Kth smallest element
// in an array
using System;

class GFG {

      // Input array
     int[] arr = { 1, 423, 6, 46, 34, 23, 13, 53, 4,1 };
 
     int occ = Convert.ToInt32(Console.ReadLine());

     int count = arr.Count(x=>x ==occ);

     Console.WriteLine("Total occurenec: "+count);            

     Console.ReadKey();
}


Output
2 occurenceof 1.

Comments

Popular posts from this blog

Input = INDIA, count each char in input string