Input day number and print day name in C
if else if - Question 3
In this question, we will see how to input a number between 1 to 7 and print the corresponding day of a week (day name) in C programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.
Q3) Write a program in C to input a number between 1 to 7 and print the corresponding day of a week (day name).
Example:
1 = Sunday
2 = Monday
3 = Wednesday
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int n;
printf("Enter a number ");
scanf("%d",&n);
if(n==1)
{
printf("Sunday");
}
else if(n==2)
{
printf("Monday");
}
else if(n==3)
{
printf("Tuesday");
}
else if(n==4)
{
printf("Wednesday");
}
else if(n==5)
{
printf("Thursday");
}
else if(n==6)
{
printf("Friday");
}
else if(n==7)
{
printf("Saturday");
}
else
{
printf("Invalid number");
}
return 0;
}
Output
Enter a number 5 Thursday