0% found this document useful (0 votes)
4 views4 pages

C# Switch Statement Example

Uploaded by

monishkumar879
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

C# Switch Statement Example

Uploaded by

monishkumar879
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SWITCH STATEMENT

[Link] a project for demonstrating switch statement.

Algorithm:

 Start

 Prompt the user to enter a number between 1 and 7.

 Read the input from the user.

 Convert the input from string to integer and store it in a variable day.

 Check the value of day using a switch or conditional statements:

 If day is 1, output "Sunday".

 If day is 2, output "Monday".

 If day is 3, output "Tuesday".

 If day is 4, output "Wednesday".

 If day is 5, output "Thursday".

 If day is 6, output "Friday".

 If day is 7, output "Saturday".

 Otherwise, output "Invalid input! Please enter a number between 1 and

7."

 End
C# code:
using System;
class Program
{
static void Main()
{
[Link]("Enter a number (1 to 7): ");
int day =
Convert.ToInt32([Link]());

switch (day)
{
case 1:
[Link]("Sunday");
break;
case 2:
[Link]("Monday");
break;
case 3:
[Link]("Tuesday");
break;
case 4:
[Link]("Wednesday");
break;
case 5:
[Link]("Thursday");
break;
case 6:
[Link]("Friday");
break;
case 7:
[Link]("Saturday");
break;
default:
[Link]("Invalid input!
Please enter a number between 1 and 7.");
break;
}
}
}

OUTPUT:

You might also like