hamzajaved

Display the Number of times value appears in array

Oct 4th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.  
  6.             //Twenty-five numbers are entered through the Keyboard into an array.
  7.             //The Number to be searched is entered through the keyboard by user
  8.             //Write a program to find if the number to be searched is present
  9.             //in an arry and if it is present , display the number of times it
  10.             //appears in array.
  11.  
  12.  
  13.             int[] arr = new int[10];
  14.  
  15.             Console.WriteLine("Enter the Values in array");
  16.             for (int i = 0; i < 5; i++)
  17.             {
  18.                 arr[i] = Convert.ToInt16(Console.ReadLine());
  19.             }
  20.             int num;
  21.             Console.WriteLine("Enter the value to be searched in array: ");
  22.             num = Convert.ToInt16(Console.ReadLine());
  23.             int count = 0;
  24.             for (int i = 0; i < 5; i++)
  25.             {
  26.                
  27.                 if(num == arr[i])
  28.                 {
  29.                     count = count + 1;
  30.                    
  31.                 }
  32.             }
  33.             Console.WriteLine("\n" + "Number of times value appeared in array is ");
  34.             Console.WriteLine(count);
  35.         }
  36.     }
Add Comment
Please, Sign In to add comment