课后作业,求活了多久的问题
#include <stdio.h>int main()
{
int y, m, d;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int i;
long count = 0, z = 0;//z算其余的天数,count用来算中间整年
printf("Please input your birthday:");
scanf("%d-%d-%d", y, m, d);
for(i = y+1; i < 2018; i ++)
{
if(i % 400 == 0 || (i % 4 ==0 && i % 10 != 0))
{
count = count + 366;
}
else
count = count + 365;
}//今天为2018-9-1,算出中间年份的天数(例如1996-8-26日出生,则上面算出1997-1-1至2018-1-1的天数)
for(i = 0; i < 9; i++)
z = z+days;//2018-1-1至2018-9-1的天数
for(i = m; i < 12; i++)
z = z+days;//以1996-8-26为例,算出1996-9-1至年末的天数
z = z + (days - d);//算出出生当天至月末的天数
count = count + z;
printf("You lived %ld days!\n", count);
return 0;
}
程序运行会报Segmentation fault,不知道错在哪里,请大神指导! scanf("%d-%d-%d", &y, &m, &d);
页:
[1]