write a program to enter a number and display the day according to the number
Answers
Answer:
c programming
Explanation:
#include<stdio.h>
int main()
{
int n;
printf("Enter a number from 1 to 7 n");
scanf("%d", &n);
if (n<=7)
{
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
printf ("SATURDAY");
}
else
printf ("Invalid Entry");
return 0;
}
Here, the program first checks the condition whether entered number n is less than or equal to 7 or not. If it is less than 7 then the number is checked against the if and else if conditions and the statement associated with the matching condition is executed. If the entered number is more than 7 then “Invalid Entry” is displayed.