Make a program that associates all 26 English alphabets A-Z with the index 1-26. User will enter a number from 1 to 26 and it will show the associated alphabet.
Make a program that associates all 26 English alphabets A-Z with the index 1-26. User
Collapse
X
-
well - never used c# but found a online fiddle to fiddle around with c# :) the basic idea could look like something like this:
note that it needs adaption to your real case - and probably correct error handling and so forth. the idea is just to use an array with the elements you want to retrieve. now the input should be an integer between 0 and the array's length which then directly can be used to acces the corresponding element in the array.Code:using System; public class Program { public static void Main() { char [] alpha = {'a', 'b', 'c', 'd'}; string txt = Console.ReadLine(); Console.WriteLine( alpha[Convert.ToInt32(txt)] ); } }Last edited by gits; Mar 22 '19, 11:59 AM.
Comment