In this C program, we will learn about how to print number of days in a month using if else ladder statement. We will take a number between 1 to 12 as input from user, where 1 corresponds to January, 2 corresponds to February and so on. We will use if else ladder statement to print number of days in any month in words.
Required Knowledge
C program to print number of days in months
#include <stdio.h> int main() { int month; printf("Enter Month Number\n"); scanf("%d", &month); /* Input Validation */ if(month < 1 || month > 12){ printf("Invalid Input !!!!\n"); return 0; } if(month == 2) { printf("28 or 29 Days in Month\n"); } else if(month == 4 || month == 6 || month == 9 || month == 11) { printf("30 Days in Month\n"); } else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { printf("31 Days in Month\n"); } return 0; }Output
Enter Month Number 2 28 or 29 Days in Month
Enter Month Number 12 31 Days in Month
Enter Month Number 9 30 Days in Month
Enter Month Number 15 Invalid Input !!!!
Related Topics