Write a program in C to input the day of the week in numeric form and display in words using if-else if anyone answer these question please reply me on fast
Answers
Answered by
1
Answer:
Why use a switch statement. For problems like this, I find a lookup table to be cleaner:
#include <stdio.h>
void main()
{
const char * const days[] = {
"Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday"
};
int day = 0, ch;
puts("Enter a day by number:");
ch = getchar();
day = ch - '0' - 1; // subtracting 1 for array indexing
if (day >= 0 && day < 7)
printf("The day you entered is %s\n", days[day]);
return;
}
Similar questions