A PHP Error was encountered

Severity: Warning

Message: fopen(/var/cpanel/php/sessions/ea-php56/PHPSESSID6lm1ea4hvdoig5hbasrbk4omgn661cs0): failed to open stream: No space left on device

Filename: drivers/Session_files_driver.php

Line Number: 174

C++ program to find total number of days in given month of year
Q:

C++ program to find total number of days in given month of year

0

C++ program to find total number of days in given month of year

While writing code in C++ programming language, sometimes we need to work with the date, this program may useful for you.

In this program, we are going to find total number of days in a month, year. Here, we are designing a function named getNumberOfDays(), function will take month and year as arguments, function will return total number of days.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

#include <iostream>
using namespace std;

//function will return total number of days
int  getNumberOfDays(int month, int year)
{
	//leap year condition, if month is 2
	if( month == 2)
	{
		if((year%400==0) || (year%4==0 && year%100!=0))	
			return 29;
		else	
			return 28;
	}
	//months which has 31 days
	else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8
	||month == 10 || month==12)	
		return 31;
	else 		
		return 30;
} 

//Main program
int main()
{
	int days=0;

	days = getNumberOfDays(2, 2016);

	cout<<endl<<"Number of Days :  "<<days;

	return 0;
}

Output

Number of Days:  29

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Most popular and Searched C++ solved programs with Explanation and Output

Similar questions


need a help?


find thousands of online teachers now
C++ program to get previous date of given date... >>
<< C++ program to set network settings for IPv6 Netwo...

A PHP Error was encountered

Severity: Warning

Message: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/cpanel/php/sessions/ea-php56)

Filename: Unknown

Line Number: 0