C# Program to Demonstrate Example of Simple If Else Statement

I hope every article can give you some new information. In that sense today we are going to know very clearly about C# Program to Demonstrate Example of Simple If Else Statement. Let’s go into our article.

C# Program to Demonstrate Example of Simple If Else Statement

C# Program to Demonstrate Example of Simple If Else Statement

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

namespace IncludeHelp
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {
            //example 1: Input age and check it's teenage or not
            int age = 0;
            Console.Write("Enter age: ");
            age = Convert.ToInt32(Console.ReadLine());

            //checking condition
            if (age >= 13 && age <= 19)
                Console.WriteLine("{0} is teenage", age);
            else
                Console.WriteLine("{0} is teenage", age);

            //example 2: Input two integer numbers and check 
            //whether first number is divisible by second or not?
            int a, b;
            Console.Write("Enter first number : ");
            a = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter second number: ");
            b = Convert.ToInt32(Console.ReadLine());

            //checking condition
            if (a % b == 0)
                Console.WriteLine("{0} is divisible by {1}", a, b);
            else
                Console.WriteLine("{0} is not divisible by {1}", a, b);

            //hit ENTER to exit the program
            Console.ReadLine();
        }
    }
}
Enter age: 17
17 is teenage
Enter first number : 120
Enter second number: 20
120 is divisible by 20

Final Words

C# Program to Demonstrate Example of Simple If Else Statement Article We hope you have all the information you need. Let me know if you have any doubts about this article. Thanks.

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