C Programming Code Examples C > If Else and Switch Case Code Examples Program to print days in a month using logical OR operator Program to print days in a month using logical OR operator The above logic is simple and easy to code. But it's lengthy and not optimal to implement. In the above solution we are performing same task for multiple conditions i.e. print 31 days for month 1, 3, 5, 7, 8, 10, 12 and print 30 days for month 4, 6, 9, 11. To perform single task on multiple condition, we use logical OR operator ||. Logical OR operator groups multiple conditions and evaluate true if any of the condition is true. You can group all conditions for 31 days together as if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12). Similarly group all conditions for 30 days as if(month==4 || month==6 || month==9 || month==11). #include <stdio.h> int main() { int month; /* Input month number from user */ printf("Enter month number (1-12): "); scanf("%d", &month); /* Group all 31 days conditions together using logical OR operator */ if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12) { printf("31 days"); } else if(month==4 || month==6 || month==9 || month==11) { /* Group all 30 days months together */ printf("30 days"); } else if(month==2) { printf("28 or 29 days"); } else { printf("Invalid input! Please enter month number between (1-12)."); } return 0; }