為什么同樣的代碼,我寫的就運(yùn)行出這個結(jié)果,還告訴我是對的,粘貼同學(xué)的就正常呢?
#include <stdio.h>
int main()
{
??? int year = 2014; //今年是2014年
??? //補(bǔ)全一下代碼
??? if(year%4==0)
??? {
??????? printf("%s\n", "今年是閏年");
??? }
??? else
??? {
??????? printf("%s\n", "今年是平年");
??? }?
??? return 0;
}
/249/5199/Dm3H/hello.c: In function 'main':
/249/5199/Dm3H/hello.c:8:9: error: stray '\357' in program
???????? printf("%s\n", "今年是閏年");
???????? ^
/249/5199/Dm3H/hello.c:8:9: error: stray '\274' in program
/249/5199/Dm3H/hello.c:8:9: error: stray '\233' in program
/249/5199/Dm3H/hello.c:9:5: error: expected ';' before '}' token
???? }
???? ^
/249/5199/Dm3H/hello.c:12:9: error: stray '\357' in program
???????? printf("%s\n", "今年是平年");
???????? ^
/249/5199/Dm3H/hello.c:12:9: error: stray '\274' in program
/249/5199/Dm3H/hello.c:12:9: error: stray '\233' in program
/249/5199/Dm3H/hello.c:13:5: error: expected ';' before '}' token
???? }?
???? ^
2016-05-07
? = ? 的意思是賦值,==的意思是等于。
/是除法,%是取余運(yùn)算。
if(year%4=0&&year/100!=0)改成
if(year%4==0&&year%100!=0)
還有標(biāo)點(diǎn)符號請 使用英文半角。
你標(biāo)題上的代碼錯在了。使用了中文符號。
printf("%s\n", "今年是閏年");分號記得用英文半角來寫。
printf("%s\n", "今年是平年");
改完了就好了。
2016-05-04
同學(xué),你好!謝謝回答,我修改了代碼如下:
#include <stdio.h>
int main()
{
???? int year = 2014; //今年是2014年
??? //補(bǔ)全一下代碼
??? if(year%4=0 && year/100!=0)
??? {
??????? printf("今年是閏年");
??? }
??? else
??? {
??????? printf("今年是平年");
??? }?
??? return 0;
}
但是運(yùn)行結(jié)果如下:
/249/5199/Dm3H/hello.c: In function 'main':
/249/5199/Dm3H/hello.c:6:14: error: lvalue required as left operand of assignment
???? if(year%4=0 && year/100!=0)
????????????? ^
/249/5199/Dm3H/hello.c:8:9: error: stray '\357' in program
???????? printf("今年是閏年");
???????? ^
/249/5199/Dm3H/hello.c:8:9: error: stray '\274' in program
/249/5199/Dm3H/hello.c:8:9: error: stray '\233' in program
/249/5199/Dm3H/hello.c:9:5: error: expected ';' before '}' token
???? }
???? ^
/249/5199/Dm3H/hello.c:12:9: error: stray '\357' in program
???????? printf("今年是平年");
???????? ^
/249/5199/Dm3H/hello.c:12:9: error: stray '\274' in program
/249/5199/Dm3H/hello.c:12:9: error: stray '\233' in program
/249/5199/Dm3H/hello.c:13:5: error: expected ';' before '}' token
???? }?
???? ^
2016-05-03
閏年的判斷是 (year%4==0&&year%100!=0),你沒寫全