scanf函数输入两次才能显示结果?

#include <stdio.h>

main()

{

int n=getchar();

int i;

int sum = 0;

scanf("%d", &n);

for (i = 0;  i <= n; i++) {

if (i % 2 == 1) { 

sum = sum + i; }

}

printf("%d\n", sum);

}


dd1231234044160
浏览 1689回答 3
3回答

望远

int n=getchar();直接把getchar()去掉int n;

慕的地8582982

UEBLZEEUORFHHNVJAJUOGNPILTTOLWFHAAZELCJCMLFTIHIYFOLNXKVOXQEJNDIMWRDWEVSFFVPFTYXYGWXGNNKWOEQQNEXUHLIFFBZHIRYRFJVOJCCTTTCZDOXTDXORBAYXMVGPAQLEGTHGFVZZXHKDBGNCVFFZIMCNPPJMVCMEBAOOAKOIYPPSRSCNBXXCGDKAAFPFYFGGXFYIZCBEIZFMDXRRJRVZQGKVSJNKJJTTOYIGKRRXTDQDYWZRESAZZZDMTANHOOSKKXXEEIYDLEVCJWYYOPKGVYPNHNMLSVUAAKDTFFCUTFWKLORFUBNOUBQQAQBOORBUKUYRANNUTBJEUPCMXHCDMCGXNSITDLMWCGNUATUXHBEKNHUDVJZBPXAQRZNWDQKHUHYDJPWHEVJTZCVWASTNBPGABLWWGEAIKBTMWJGNGJJHSBOBPOLZMKYQWFCTZGDXKREDOLICANXLODZWAXEBJCWDRFOGWTOVOREJPQBQXWQDNRMWSZLVSPZQXZYVIQWMSRVFGPSSJPXAUFJXQWQNKTUZMKTJGJGTGNREVAADBZNURRZMKYBLZUYXQNEKGGOYIRRUGXKQDDUQISIQNDGQGGVTKRECBJKRBYVOYVWLORPXTTHQOJEEZWQXXRUYTLTFJZWWUXEBVLLDULBVYBPYIZZNYYYBDVEHKKIIRWWADBMCTHFFBBFQIYSXLCLLVIKKAWQFFTTWJQAEEOIWCCVPCLDPFWWZLXBWOLYVMWWTTNHYGDGGOOLOXLPGZDUNXLKKCSLRYVSSYYZIFZWMDRUILYPVVBGUZMWMTXXBSJZKADCXAGNPGTEUUTKQSAGGFMMLKILTKCZMMMTGWQWUEFOYIOOPFEKQXNRULHAE

Will_木

用了n=getchar()和scanf("%d",&n) 就要输入两次咯
打开App,查看更多内容
随时随地看视频慕课网APP