stkirov

04.NumberInArrayWithTests

Jan 16th, 2013
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2.  
  3. public class NumberInArrayWithTests
  4. {
  5.     public static decimal numberToCheck;
  6.     public static int counter;
  7.  
  8.     public static void CountAppearances(decimal[] array)
  9.     {
  10.         for (int i = 0; i < array.Length; i++)
  11.         {
  12.             if (array[i]==numberToCheck)
  13.             {
  14.                 counter++;
  15.             }
  16.         }
  17.     }
  18.  
  19.     static void Main()
  20.     {
  21.         Console.Write("Enter the number which appearance you wish to count:");
  22.         numberToCheck = decimal.Parse(Console.ReadLine());
  23.         decimal[] array = { 1, 2, 5, 2, 6, 7, 3, 2, 7, 8, 2 };
  24.         CountAppearances(array);
  25.         Console.WriteLine("The number {0} appears {1} of times in the array", numberToCheck, counter);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment