Simple C Program for Switch Case to Find Weekdays Name with...
On this page (6sections)
About this program
This is an example program in simple example programs. Read the concept first: Hello World - Simple C Program, then study the code and output below.
Definition
In c programming language, switch statement is a type of selection mechanism used to allow block code among many alternatives.
Simply,It changes the control flow of program execution via a mutliple block. we can use for Nested if.. else statement.
Syntax:
switch ( <variable> ) {
case value1:
//Block 1 Code Here
break;
case value2:
//Block 1 Code Here
break;
...
default:
Code to execute for not match case
break;
}
Simple C Program for Switch case to Find weekdays name with weekday number
/*## Simple C Program for Switch case to Find weekdays name with weekday number */
/*## Basic Programs,Find weekdays C Programming*/
#include <stdio.h>
int main() {
// Declare Variables
int day;
//Read Day Value
printf("Enter weekday number (1-7): ");
scanf("%d",&day);
//Print Day with Switch case
switch(day)
{
case 1:
printf("1 - Sunday");
break;
case 2:
printf("2 - Monday");
break;
case 3:
printf("3 - Tuesday");
break;
case 4:
printf("4 - Wednesday");
break;
case 5:
printf("5 - Thursday");
break;
case 6:
printf("6 - Friday");
break;
case 7:
printf("7 - Saturday");
break;
default:
printf("%d : Invalid Day Option",day);
}
return 0;
}
Sample Output:
Enter weekday number (1-7): 4
4 - Wednesday
Enter weekday number (1-7): 10
10 : Invalid Day Option
Related Pages
Learn the concept first, then study the code:
- C Programs — Browse all C Programs.
- Hello World - Simple C Program — Tutorial — your first C program explained line by line.
- Hello World C Language Example Program — More in simple example programs.
- If Statement Example Program In C Programming Language — More in simple example programs.