C++ 实例 - 判断闰年

闲来无事写个小程序。

#include <iostream> 
using namespace std; 
int main() 
{ 
	int year; 
	cout << "输入年份: "; 
	cin >> year; 
	if (year % 4 == 0) 
	{ 
		if (year % 100 == 0) 
		{ 
			//这里如果被 400 整数是闰年 
			if (year % 400 == 0) 
				cout << year << " 是闰年"; 
			else 
				cout << year << " 不是闰年"; 
		} 
		else 
			cout << year << " 是闰年"; 
	} 
	else 
		cout << year << " 不是闰年"; 
	return 0; 
}

猜你喜欢

转载自blog.csdn.net/yuupengsun/article/details/107881256
今日推荐