HI WELCOME TO SIRIS

C# program to print alphabets

Leave a Comment
This c# program prints both upper and lower case alphabets using 2 different approaches.

using System;

namespace SamplePrograms{    class Alphabets    {        public static void Main()        {            // Loop from a thru z (lower case alphabets)            for (char alphabet = 'a'; alphabet <= 'z'; alphabet++)            {                Console.Write(alphabet + " ");            }

            //Another way to print lower case alphabets            //for (int i = 0; i < 26; i++)            //{            //    Console.Write(Convert.ToChar(i + (int)'a') + " ");            //}

            Console.WriteLine();

            // Loop from A thru Z (upper case alphabets)            for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++)            {                Console.Write(alphabet + " ");            }

            //Another way to print uppercase case alphabets            //for (int i = 0; i < 26; i++)            //{            //    Console.Write(Convert.ToChar(i + (int)'A') + " ");            //}                        Console.ReadLine();        }    }}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.