//输入一个年份,判断这一年有多少秒;
//分别判断平年和闰年
//闰年能被4整除并且不能被100整除或者可以被400整除
#include<iostream>
using namespace std;
void second(int year)
{
if((year%4 == 0 && year%100 != 0) ||year%400 == 0)//判断是否是闰年
{
int n = 366*12*3600;
cout<<year<<" "<<"have"<<" "<<n<<" "<<"second"<<endl;
}
else
{
int n = 365*12*3600;
cout<<year<<" "<<"have"<<" "<<n<<" "<<"second"<<endl;
}
}
void main()
{
while(1)
{
int year;
cout<<"please input one year:";
scanf("%d",&year);
if(year == -1)//输入-1程序退出
{
cout<<"quit!"<<endl;
break;
}
second(year);
}
}
计算一年有多少秒
最新推荐文章于 2022-10-23 22:55:52 发布