这题已经明白了 谢谢大家帮我找错误!!!感谢
[此贴子已经被作者于2006-3-21 18:05:13编辑过]
[CODE]
#include <stdio.h>
int days[][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}};
void main()
{
int year,month,day,leap,i;
printf("please input year,month,day:\n");
scanf("%d%d%d",&year,&month,&day);
leap=(year%4 == 0 && year%100!=0) || year%400 == 0 ?1:0;
for(i=0;i<month-1;i++)
day+=days[leap][i];
printf("\n%d --- %d\n",year,day);
}
[/CODE]
我感觉算法是对的..
程序还有错吗?
难道是哪个day没初值..
我这儿没C不能调试..
IF后面要叫“;”么
怎么学的基本工!
搞了半天..这问题
[CODE]
#include <stdio.h>
int days[][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}};
void main()
{
int year,month,day,leap,i;
printf("please input year,month,day:\n");
scanf("%d:%d:%d",&year,&month,&day);
leap=(year%4 == 0 && year%100!=0) || year%400 == 0 ?1:0;
for(i=0;i<month-1;i++)
day+=days[leap][i];
printf("\n%d --- %d\n",year,day);
}
[/CODE]
没有问题,但是我觉得输入格式可以改一下,因为不太习惯。