Sample Qustion 5

Write a C++ program to read the year and the month number from user. Output number of days in that month. Consider the concept leap year.

#include<iostream>
using namespace std;
int main() {
   int year , month;
   cout << "Enter year : " ;
   cin >> year;
   cout << "Enter Month : " ;
   cin >> month;

   if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
      cout<<year<<" is a leap year" << endl;
   else
      cout<<year<<" is not a leap year" << endl;

    if( month == 2)
    {
        if((year%400==0) || (year%4==0 && year%100!=0))
            cout << "29 days in this month" << endl;
        else
            cout << "28 days in this month" << endl;
    }
    //months which has 31 days
    else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8
    ||month == 10 || month==12)
        cout << "31 days in this month" << endl;
    else
        cout << "30 days in this month" << endl;



    return 0;
}
 
download file  cpp file

do you have any qustion please comment 



click the advertisement to help for me ....




Comments

Popular posts from this blog

Sample Qustion 11

Sample Qustion 1