C++ program to enter month number and print number of days in month.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

C++ program to enter month number and print number of days in month. I have used DEV-C++ compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<iostream>
using namespace std;

int main()
{
    int month;
    cout << "Enter month number (1-12):";
    cin >> month;

    if(month == 1)
    {
        cout << "Enter month : January " <<endl;
        cout << "No. of days : 31 days" <<endl;
    }
    else if(month == 2)
    {
        cout << "Enter month : February " <<endl;
        cout << "No. of days :  28 or 29 days" <<endl;
    }
    else if(month == 3)
    {
        cout << "Enter month : March " <<endl;
        cout << "No. of days :  31 days" <<endl;
    }
    else if(month == 4)
    {
        cout << "Enter month : April " <<endl;
        cout << "No. of days :  30 days" <<endl;
    }
    else if(month == 5)
    {
        cout << "Enter month : May " <<endl;
        cout << "No. of days :  31 days" <<endl;
    }
    else if(month == 6)
    {
        cout << "Enter month : June " <<endl;
        cout << "No. of days :  30 days" <<endl;
    }
    else if(month == 7)
    {
        cout << "Enter month : July " <<endl;
        cout << "No. of days :  31 days" <<endl;
    }
    else if(month == 8)
    {
        cout << "Enter month : August " <<endl;
        cout << "No. of days :  31 days" <<endl;
    }
    else if(month == 9)
    {
        cout << "Enter month : September " <<endl;
        cout << "No. of days :  30 days" <<endl;
    }
    else if(month == 10)
    {
        cout << "Enter month : October " <<endl;
        cout << "No. of days :  31 days" <<endl;

    }
    else if(month == 11)
    {
        cout << "Enter month : November " <<endl;
        cout << "No. of days :  30 days" <<endl;
    }
    else if(month == 12)
    {
        cout << "Enter month : December " <<endl;
        cout << "No. of days :  31 days" <<endl;
    }
    else
    {
        cout << "Invalid input! Please enter month number between (1-12).";
    }

    return 0;

}

Result

C language techstudy.org

     





Related Topics




Popular Posts