[問題] for迴圈
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
c++
問題(Question):
想請問以下的i不是從0開始到1嗎,為什麼cout出來後值會是2呢
預期的正確結果(Expected Output):
n=1 a=-0.35
錯誤結果(Wrong Output):
n=2 a=-0.35
程式碼(Code):(請善用置底文網頁, 記得排版)
#include<iostream>
#include<cmath>
using namespace std ;
float main()
{ int i;
float f=-0.45;
for(i=0;i<=1;i++)
f=3*f+pow((float)1/2,(int)i)+0.2*i;
cout<<"n="<<i<<" a="<<f<<endl;
system("pause");
return -0.45;
補充說明(Supplement):
i每次都跟我想要的值加1,再算這個遞迴很奇怪
剛接觸程式語言,還請大大們解惑一下QQ
另外請問有辦法把i=0 和 i=1 的結果同時cout出來
而不是只看到i=1的結果嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 27.105.6.86
→
03/16 05:00, , 1F
03/16 05:00, 1F
→
03/16 05:01, , 2F
03/16 05:01, 2F
→
03/16 05:02, , 3F
03/16 05:02, 3F
→
03/16 05:02, , 4F
03/16 05:02, 4F
→
03/16 16:07, , 5F
03/16 16:07, 5F
→
03/18 18:05, , 6F
03/18 18:05, 6F