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

5 (100%) 1 vote

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 Number Weekday Name
0 Sunday
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday

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”]

For any query or issue, feel free to discuss on http://discuss.eduguru.in

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: