-
红颜莎娜
1#include <iostream> 1using namespace std; 12345int main(){ int sum_day(int month,int day); int is_leap(int year); int year,month,day,days; 12 cout<<"Enter date(for example:2015 1 14):\n"; cin>>year>>month>>day; 123 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"; 12 return 0;} 12345678int 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;} 12345int is_leap(int year){ return ((year%4==0&&year%100!=0) ||year%400==0);}我在code blocks上运行没有问题
-
慕桂英546537
123456789101112131415161718192021222324252627282930313233#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;}
-
互换的青春
# 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;}没调试过,机子上暂时没工具,应该是没问题了。你试试