Advertisement
ScorpS

Index Of Each Letter

Jan 7th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1.  
  2. //Write a program that creates an array containing all letters from the alphabet (A-Z).
  3. //Read a word from the console and print the index of each of its letters in the array.
  4.  
  5. using System;
  6.  
  7. class IndexOfEachLetter
  8. {
  9.     static void Main()
  10.     {
  11.         char[] alphabet = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
  12.                            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
  13.         string word = Console.ReadLine();
  14.  
  15.         foreach (char letter in word)
  16.         {
  17.             for (int index = 0; index < alphabet.Length; index++)
  18.             {
  19.                 if (letter == alphabet[index])
  20.                 {
  21.                     Console.WriteLine("letter {0} is with index {1}", letter, index);
  22.                 }
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement