use of switch statement in C#

 //Program is constructed under Aryan Computers, Barshi 

For Example: Write a program demonstrates the use of switch statement.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication3

{

classProgram

    {

staticvoid Main(string[] args)

        {

int a, b,c;

char option;

Console.Write("Enter the Value for A : ");

            a = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter the Value for B : ");

            b = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter the Value for C : ");

            c = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("------------------------------------");

Console.WriteLine("Menu Driven Program");

Console.WriteLine("1. Largest Number ");

Console.WriteLine("2. Smllest Number");

Console.WriteLine("------------------------------------");

Console.Write("Enter the Operation you want to perform:");

            option = Convert.ToChar(Console.ReadLine());

switch (option)

            {

case'1':

if (a > b && a > c)

                    {

Console.WriteLine("A is largest : {0}", a);

                    }

elseif(b>a && b>c)

                    {

Console.WriteLine("B is largest : {0}", b);

                    }

elseif(c>a && c>b)

                    {

Console.WriteLine("C is largest : {0}", c);

                      }

break;

case'2':

if (a < b && a < c)

                    {

Console.WriteLine("A is smallest : {0}", a);

                    }

elseif(b<a && b<c )

                    {

Console.WriteLine("B is smallest : {0}", b);

                    }

elseif(c<a && c<b)

                    {

Console.WriteLine("C is smallest : {0}", c);

                      }

break;

 

default:

Console.WriteLine("Invalid Option");

break;

            }

Console.ReadLine();

 

        }

    }

}

Output:

Comments

Popular posts from this blog

simple program C#

Regular Expression Validator Control in asp.net

two dimension array in C#