Write a C C++ program to find number of days in a month

Write a C C++ program to find number of days in a month

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

Switch statement और multibranching statements के बारे में अधिक जानने के लिए देखें—Switch statements in C

Flowchart to find number of days in a month

Flowchart to find number of days in months

C program to find number of days in a month

#include<stdio.h>
int main()
{
    int month;
    printf("Enter month number: ");
    scanf("%d",&month);
    switch(month)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        printf("31 days");
        break;
        case 4:
        case 6:
        case 9:
        case 11:
        printf("30 days");
        break;
        case 2:
        printf("28 days");
        break;
        default:
        printf("Invalid month number");
    }
    return 0;
}

C++ program to find number of days in a month

#include<iostream>
using namespace std;
int main()
{
    int month;
    cout<<"Enter month number: ";
    cin>>month;
    switch(month)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        cout<<"31 days";
        break;
        case 4:
        case 6:
        case 9:
        case 11:
        cout<<"30 days";
        break;
        case 2:
        cout<<"28 days";
        break;
        default:
        cout<<"Invalid month number";
    }
    return 0;
}

Output of C C++ program to find number of days in a month

Enter month number: 1
31 days
Enter month number: 6
30 days
Enter month number: 15
Invalid month number

Related programs in C and C++

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Total percent and division (else if ladder)
  7. Greatest in three numbers (nested if)
  8. Simple calculator program (switch case single case)
  9. Switch between Mon to Sun (switch case single case)
  10. Checking vowel or consonant (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer