C switch case program to read weekday number and print weekday name

C switch case program to read weekday number and print weekday name

This program will read weekday number (0-6) and print weekday name

(Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday)

 

Weekday NumberWeekday Name
0Sunday
1Monday
2Tuesday
3Wednesday
4Thursday
5Friday
6Saturday

Program Example:

#include <stdio.h>

int main()
{
int weekDay;

printf(“Enter weekday number (0-6): “);
scanf(“%d”,&weekDay);

switch(weekDay)
{
case 0:
printf(“Sunday”);
break;
case 1:
printf(“Monday”);
break;
case 2:
printf(“Tuesday”);
break;
case 3:
printf(“Wednesday”);
break;
case 4:
printf(“Thursday”);
break;
case 5:
printf(“Friday”);
break;
case 6:
printf(“Saturday”);
break;
default:
printf(“This is not a valid weekday number.”);
}
printf(“\n”);
return 0;
}

This Program is using Switch case and the switch case program flow as below:

switch case flow chart
switch case flow chart

Output of above c program

First Run:
Enter weekday number (0-6): 3
Wednesday

Second run:
Enter weekday number (0-6): 9
This is not a valid weekday number.

 

[xyz-ihs snippet=”Discuss”]

Leave a Reply