C的困难
#include<stdio.h>int main()
{
int year;
int month;
scanf("%d%d",year,month);
if((month == 1)||(month == 3)||(month == 5)||(month == 7)||(month == 8)||(month == 10)||(month == 12))
{
printf("31");
}
if((month == 4)||(month == 6)||(month == 9)||(month == 11))
{
printf("30");
}
if(month == 2)
{
if(((year%4 == 0)&&(year%100 != 0))||((year%100 == 0)&&(year%400 == 0)))
{
printf("29");
}
else
{
printf("28");
}
}
return 0;
}
运行后的结果::
2023 2
--------------------------------
Process exited after 3.571 seconds with return value 3221225477
请按任意键继续. . .
怎么会这样{:5_104:} 这段代码的问题在于scanf函数中的参数应该是变量的地址,而不是变量本身。需要将scanf函数的第二个和第三个参数改为&year和&month,即可正确读取输入的年份和月份。修改后的代码如下:
#include<stdio.h>
int main()
{
int year;
int month;
scanf("%d%d", &year, &month);
if((month == 1)||(month == 3)||(month == 5)||(month == 7)||(month == 8)||(month == 10)||(month == 12))
{
printf("31");
}
if((month == 4)||(month == 6)||(month == 9)||(month == 11))
{
printf("30");
}
if(month == 2)
{
if(((year%4 == 0)&&(year%100 != 0))||((year%100 == 0)&&(year%400 == 0)))
{
printf("29");
}
else
{
printf("28");
}
}
return 0;
}
找到问题了,我的输入函数用错了,没有地址赋予符
页:
[1]