[原创]初学c语言,做的第一个小程序(40分钟完成)
输入任意年月日,判断这一天是那年的第几天.以下是我的源代码:
main()
{
int y,m,d,s=0,i=0,j=0;
clrscr();
printf("Please input the YEAR MONTH DAY:\n");
scanf("%d %d %d",&y,&m,&d);
if(y%4==0&&y%100!=0||y%400==0) i=1;
if((d<1||d>31)||(d>28&&i!=1)||(d>29&&i==1))
{
printf("Input Error!!!");
goto loop;
}
switch (m)
{
case 1: s=0+d;break;
case 2: s=31+d;break;
case 3: s=31+d+i+28;break;
case 4: s=31+i+28+31+d;break;
case 5: s=31+i+28+31+30+d;break;
case 6: s=31+i+28+31+30+31+d;break;
case 7: s=31+i+28+31+30+31+30+d;break;
case 8: s=31+i+28+31+30+31+30+31+d;break;
case 9: s=31+i+28+31+30+31+30+31+31+d;break;
case 10: s=31+i+28+31+30+31+30+31+31+30+d;break;
case 11: s=31+i+28+31+30+31+30+31+31+30+31+d;break;
case 12: s=31+i+28+31+30+31+30+31+31+30+31+30+d;break;
default: printf("Input Error!!!"); goto loop;
}
j=((s+10)%10);
switch (j)
{
case 1: printf("DATE %d.%d.%d is the %dst day of year %d.",y,m,d,s,y);break;
case 2: printf("DATE %d.%d.%d is the %dnd day of year %d.",y,m,d,s,y);break;
case 3: printf("DATE %d.%d.%d is the %drd day of year %d.",y,m,d,s,y);break;
default: printf("DATE %d.%d.%d is the %dth day of year %d.",y,m,d,s,y);
}
loop: getch();
}
小弟是c的初学者, 这是我做的第一个有点用的程序, 各位大侠帮忙看看,指点一下,还有那些需要改进的地方.