課程
/后端開發(fā)
/C
/C語言入門
為什么number=6/5*number不可以
2018-06-11
源自:C語言入門 4-7
正在回答
6/5中,6和5都為整型,除法結(jié)果也為整型1 ,number=6/5*number就變?yōu)閚umber=1*number,從而陷入死循環(huán)。解決方法也很簡單,把6/5寫為6.0/5或6/5.0或6.0/5.0即可,除法結(jié)果就變?yōu)榱烁↑c(diǎn)型1.2
#include <stdio.h>
int main()
{
? ? int number=200;
? ? int year=2014;
? ? do{
? ? ? year++; ? ??
? ? ? number*=1.2; ? ? ? ?
? ? }while(number<1000);?
? ? printf("到%d年招工規(guī)模突破1000人\n", year);
? ? return 0;
}
INT型,右邊是float型
舉報(bào)
C語言入門視頻教程,帶你進(jìn)入編程世界的必修課-C語言
2 回答while和do-while
1 回答do while 和while
1 回答do while()
2 回答do while
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-08-04
6/5中,6和5都為整型,除法結(jié)果也為整型1 ,number=6/5*number就變?yōu)閚umber=1*number,從而陷入死循環(huán)。解決方法也很簡單,把6/5寫為6.0/5或6/5.0或6.0/5.0即可,除法結(jié)果就變?yōu)榱烁↑c(diǎn)型1.2
2018-07-16
#include <stdio.h>
int main()
{
? ? int number=200;
? ? int year=2014;
? ? do{
? ? ? year++; ? ??
? ? ? number*=1.2; ? ? ? ?
? ? }while(number<1000);?
? ? printf("到%d年招工規(guī)模突破1000人\n", year);
? ? return 0;
}
2018-06-12
INT型,右邊是float型