C语言编写某一天是这一年的第几天
#include<stdio.h>
int calculate(int reg,int month,int day);
void main(){
int year;
int month;
int day;
int reg;
printf("input year: ");
scanf("%d",&year);
if(year<0) year=-year;
if(year%4==0&&year%100!=0) reg=0;
else if(year%100==0&&year%400!=0) reg=0;
else reg=1;
month: printf("input month: ");
scanf("%d",&month);
if(month<=0||month>12) {
printf("error input!\n");
goto month;
}
day:
printf("input day: ");
scanf("%d",&day);
if(calculate(reg,month,day)==0) goto day;
else printf("%d\n",calculate(reg,month,day));
}
int calculate(int reg,int month,int day){
int value=0;
int data1[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int data2[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int *a;
if(reg==0) a=data1;
else a=data2;
if(a[month-1]<day||day<=0) return 0;
else {
for(int i=1;i<month;i++) value=value+a[i-1];
value=value+day;
return value;
}
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |