Advertisement
Naralex

Arrays-IndexOfGivenElement

Jan 15th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.43 KB | None | 0 0
  1. using System;
  2.  
  3. class IndexOfGivenElement
  4. {
  5.     static void Main()
  6.     {
  7.         int[] arr = new int[5] {11 , 15, 17, 20, 29};
  8.         int elIndex = 29;
  9.         int count = 0;
  10.  
  11.         for (int i = 0; i < arr.Length; i++)
  12.         {
  13.             count++;
  14.             if (arr[i] == elIndex)
  15.             {
  16.                 Console.WriteLine("The number [{0}] is in position {1}", elIndex, i);
  17.             }
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement