+ 1

what have i to do, if i want that the program always writes for example : 0+1 1+2 3+3 6+4 10+5 15+6 ... because now it just writes 1 3 6 10 15 ... and maybe if it works, can i make then 0+1=1 1+2=3 3+3=6 6+4=10 #include <iostream> using namespace std; int main(){ int i; int sum = 0; for (i = 1; i <= 100; i++){ sum = sum+i; cout<<sum<<endl; } cout<<sum; return 0; }

18th Jul 2016, 12:59 PM
Peter Müller
Peter Müller - avatar
5 Respuestas
+ 1
Just to add on to this, a shorter and alternative to sum = sum + i Would be sum += i Glad you got it sorted.
18th Jul 2016, 2:48 PM
Cohen Creber
Cohen Creber - avatar
+ 1
this q&a forum is so awesome todays morning i never heared from c++ :^) i love u guys
18th Jul 2016, 2:50 PM
Peter Müller
Peter Müller - avatar
0
{ cout<<sum<<"+"<<i<<"="; sum=sum+i; cout<<sum<<"\n"; }
18th Jul 2016, 1:42 PM
Learner
Learner - avatar
0
THANKS!!!
18th Jul 2016, 1:55 PM
Peter Müller
Peter Müller - avatar
0
cout<<sum<<'+'<<i<<'='<<sum+=i<<endl;
19th Jul 2016, 12:13 PM
_Geometry dash_ _Roh_ (AKA NovaRate0315)
_Geometry dash_ _Roh_ (AKA NovaRate0315) - avatar