3 回答
TA贡献1842条经验 获得超12个赞
1 | #include <iostream> |
1 | using namespace std; |
1 2 3 4 5 | int main() { int sum_day(int month,int day); int is_leap(int year); int year,month,day,days; |
1 2 | cout<<"Enter date(for example:2015 1 14):\n"; cin>>year>>month>>day; |
1 2 3 | days=sum_day(month,day); if(is_leap(year)&&month>2) days+=1; |
1 | cout <<year<<"/"<<month<<"/"<<day<<"is the "<<days<<" day in this year!\n"; |
1 2 | return 0; } |
1 2 3 4 5 6 7 8 | int sum_day(int month,int day) { int day_tab[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int i; for(i=1;i<month;i++) day+=day_tab[i]; return day; } |
1 2 3 4 5 | int is_leap(int year) { return ((year%4==0&&year%100!=0) ||year%400==0); } 我在code blocks上运行没有问题 |
TA贡献1848条经验 获得超10个赞
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include<iostream> using namespace std; int d[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31} }; int days(int m,int a=0) { int sumday=0; for(int i=0;i<m-1;++i) sumday+=d[a][i]; return sumday; } int main() { int day=0,month=0,year=0; cout<<"day :";cin>>day; cout<<"month :";cin>>month; cout<<"year :";cin>>year; int a=0; // 闰年判断 if((year%4==0&&year%100!=0)||year%400==0)a=1; switch(month) { case 1:case 2: case 3:case 4: case 5:case 6: case 7:case 8: case 9:case 10: case 11:case 12: cout<<days(month,a)+day<<endl; default: break; }
return 0; } |
TA贡献1797条经验 获得超6个赞
# include <stdio.h>
# include <conio.h>
int sum_day(int month, int day);
int leap(int year);
void main()
{
int year, month, day;
int days;
printf("请输入日期(年,月,日):");
scanf("%d, %d, %d", &year, &month, &day);
printf("%d年%d月%d日", year, month, day);
days = sum_day(month, day);
if(leap(year) && month>=3)
days = days + 1;
printf("是该年的第%d天.\n", days);
getch();
}
static int day_tab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum_day(int month, int day)
{
int i;
for(i=1; i<month; i++)
day = day + day_tab[i];
return day;
}
int leap(int year)
{
int leap;
leap = (year%4==0&&year%100!=0)||(year%400==0);
return leap;
}
没调试过,机子上暂时没工具,应该是没问题了。你试试
- 3 回答
- 0 关注
- 2071 浏览
添加回答
举报