C Program to Print Days of Week in Words using If Else Ladder Statement

  • Write a C program to print days of week using if else ladder statement.

Required Knowledge

In this program, 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.


C program to print days of week in words

/*
 * C program to print day of week name 
 */  
  
#include <stdio.h> 
  
int main() {  
    int day;   
    /* 
     * Take the Day number as input form user  
     */  
    printf("Enter Day Number (1 = Monday ..... 7 = Sunday)\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 (1 = Monday ..... 7 = Sunday)
4
Thursday
Enter Day Number (1 = Monday ..... 7 = Sunday)
7
Sunday
Enter Day Number (1 = Monday ..... 7 = Sunday)
12
Invalid Input !!!!

Related Topics
C Program to Print Number of Days in a Month using If Else Ladder Statement
C Program to Enter Cost Price and Selling Price and Calculate Profit or Loss
C Program to Check Whether a Triangle is Valid or Not given Sides of Triangle
C Program to Find Total, Average and Percentage Marks of Subjects
C Program to Calculate Compound Interest
C Program to Find Maximum of Three Numbers using Conditional Operator
C program to find hcf and lcm of two numbers
C program to check armstrong number
C Program to Read an Amount and Find Number of Notes
List of all C programs