#include<iostream>
using namespace std;
//定义结构体变量,输入年月日能计算并输出该日在本年是第几天,编写一个函数days
struct Days
{
int year;
int month;
int day;
};
int days(int y, int m, int d)
{
int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 },day_sum=0;
for (int i = 0; i < m- 1; i++)
day_sum += days[i];
day_sum += d;
if ((y% 4 == 0 && y % 100 != 0) || y % 400 == 0)
if (m > 1)
day_sum += 1;
return day_sum;
}
int main()
{
Days Date;
cout << "请输入年,月,日:";
cin >> Date.year >> Date.month >> Date.day;
cout << Date.year << "/" << Date.month << "/" << Date.day << "是当年的第" << days(Date.year,Date.month,Date.day) << "天!" << endl;
return 0;
}
谭浩强c++第三版7-2
最新推荐文章于 2021-05-23 06:29:01 发布