Sunday, December 28, 2014

Program to show the use of if and if – else statement

8:38 PM - By azeheruddin khan 0

Description: if and if- else are conditional constructs which are used to select a particular statement or a block of statements for execution from multiple statements or multiple blocks of statements based on the result obtained after evaluating an expression or condition. If this condition or expression is satisfied i.e. it becomes true then, that particular statement is executed else another statement is executed.

Example:

using System;

namespace ArithmeticExample
{
    class Program
    {
        static void Main(string[] args)
        {
            int age;
            Console.Write("Enter the age of the person:");
            age = Convert.ToInt32(Console.ReadLine());
            if (age >= 18)
            {
                Console.WriteLine("the person is elgible to vote");
            }
            if (age < 18)
            {
                Console.WriteLine("the person is not eligible to vote");
            }
            if (age >= 20)
            {
                Console.WriteLine("the person is elgible to participate in elections");
            }
            else if (age < 20)
            {
                Console.WriteLine("the person is not elgible to contest for elections");
            }
            Console.ReadLine();

        }
    }
}


Output:






About the Author

I am Azeheruddin Khan having more than 6 year experience in c#, Asp.net and ms sql.My work comprise of medium and enterprise level projects using asp.net and other Microsoft .net technologies. Please feel free to contact me for any queries via posting comments on my blog,i will try to reply as early as possible. Follow me @fresher2programmer
View all posts by admin →

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

adsense

© 2014 Fresher2Programmer. WP Theme-junkie converted by Bloggertheme9
Powered by Blogger.
back to top