4.cpp

来自「经典C语言程序设计100例1-10 如【程序1】 题目:有1、2、3、4」· C++ 代码 · 共 29 行

CPP
29
字号
/*---------------------------------------例题4-------------------------------------------------------------------*/


#include <iostream>

using namespace std;

int main()
{
	int _year, _month, _day;
	int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};//用数组存储非闰年的天数

	cout<<"Please input the year:"<<endl;
	cin>>_year;
	cout<<"Please input the month:"<<endl;
	cin>>_month;
	cout<<"Please input the day:"<<endl;
	cin>>_day;

	if(_year % 4 == 0 && _year / 100 != 0 || _year % 400 == 0) //判断是否是闰年
		day[1] ++;                                            //如果是闰年,二月份是29天
	for(int i = 0; i<_month - 1; i++)
		_day += day[i];                                       
	cout<<"It is day  "<<_day<<"  of year  "<<_year<<endl;
	return 0;
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?