C# Program to Demonstrate Example of Nested If Else Statement

C# Program to Demonstrate Example of Nested If Else Statement There may be many doubts when it comes to this article. We hope that after reading this article all doubts will be resolved. Let’s go to the article.

C# Program to Demonstrate Example of Nested If Else Statement

C# Program to Demonstrate Example of Nested If Else Statement

// C# program to demonstrate example of 
// nested if else statement 
using System;
using System.IO;
using System.Text;

namespace IncludeHelp
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {
            //input a character and check whether it is vowel or consonant 
            //but before it - check input character is an aplhabet or not
            char ch;
            Console.Write("Enter a character: ");
            ch = Console.ReadLine()[0];

            //check ch is an alphabet or not
            if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z')){
                Console.WriteLine("{0} is a valid alphabet", ch);
                //checking for vowel or consonant
                if (ch == 'A' || ch == 'a' || ch == 'E' || ch == 'e' ||
                    ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o' ||
                    ch == 'U' || ch == 'u')
                {
                    Console.WriteLine("{0} is a vowel", ch);
                }
                else
                {
                    Console.WriteLine("{0} is a consonant", ch);
                }
            }
            else{
                Console.WriteLine("{0} is not a valid alphabet",ch);
            }
			
            //hit ENTER to exit the program
            Console.ReadLine();
        }
    }
}
First run:
Enter a character: X
X is a valid alphabet
X is a consonant

Second run:
Enter a character: u
u is a valid alphabet
u is a vowel

Third run:
Enter a character: $
$ is not a valid alphabet

Final Words

C# Program to Demonstrate Example of Nested If Else Statement We hope all your doubts about this topic will be resolved. See you again in the next article Thank you.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment