#13269: 請問這樣寫是錯在哪裡?


eechiu (eechiu)

學校 : 高雄市立新莊高級中學
編號 : 60806
來源 : [140.113.123.166]
最後登入時間 :
2022-02-15 21:38:56

#include<iostream>
using namespace std;
int main()
{
int d,ans,count1,a;
while(cin>>d)
{
count1=1;
a=1;//第一項
ans=1;
for(int i=d;count1<=49;i=i+d)
{
a+=i;//算出各項
ans+=a;//加總各項

count1+=1;
}

cout<<ans<<endl;

}
return 0;
}

 

#13276: Re:請問這樣寫是錯在哪裡?


anandrewboy70900 (ShowTsai)

學校 : 國立中央大學
編號 : 27736
來源 : [203.204.218.144]
最後登入時間 :
2025-05-29 22:24:26

for(int i=1;count1<=49;i=i+d)

 
#13286: Re:請問這樣寫是錯在哪裡?


eechiu (eechiu)

學校 : 高雄市立新莊高級中學
編號 : 60806
來源 : [140.113.123.166]
最後登入時間 :
2022-02-15 21:38:56

for(int i=1;count1<=49;i=i+d)

 



過了 感謝樓上