In this C program, we will learn how to print days of week in words using if else ladder statement.
We will take a number between 1 to 7 as input from user, where 1 corresponds to Monday, 2 corresponds to Tuesday and so on. We will use if else ladder statement to print name of day in words.
Required Knowledge
C program to print days of week in words
#include <stdio.h> int main() { int day; printf("Enter Day Number\n"); scanf("%d", &day); /* Input Validation */ if(day < 1 || day > 7){ printf("Invalid Input !!!!\n"); return 0; } if(day == 1) { printf("Monday\n"); } else if(day == 2) { printf("Tuesday\n"); } else if (day == 3) { printf("Wednesday\n"); } else if(day == 4) { printf("Thursday\n"); } else if(day == 5) { printf("Friday\n"); } else if(day == 6) { printf("Saturday\n"); } else { printf("Sunday\n"); } return 0; }Output
Enter Day Number 4 Thursday
Enter Day Number 7 Sunday
Enter Day Number 12 Invalid Input !!!!
Related Topics