Print Friendly and PDF
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 will enter a number from 1 to 26 and it will show the associated alphabet.

Solution:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace alpha
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Number");
            while (true)
            {

                int number = Convert.ToInt32(Console.ReadLine());
                char[] alpha = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };

                if (number > 0 && number <= 26)
                {
                    for (int i = 1; i <= alpha.Length; i++)
                    {
                        if (i == number)
                        {
                            Console.WriteLine(alpha[i].ToString());
                        }
                    }

                }
                else
                {
                    Console.WriteLine("Invalid input");
                }

            }
            Console.ReadLine();
        }
    }
}


zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: