+ 2

How to find the sum of following series using "1+(1+2)+(1+2+3)+(1+2+3+4)+.......N" the value of N is entered by the user.

Question regarding loop in C++. Making a program on series.

29th Oct 2017, 4:25 PM
S-Y 007
S-Y 007 - avatar
4 odpowiedzi
+ 4
#include <iostream> using namespace std; int main () { int n; cin>>n; int answer =0, before=0; for (int i=1; i <=n: i++) { before += i; answer += before; } cout<<answer <<endl; return 0; } // I dont compile and run my code, correct me if i wrong
29th Oct 2017, 5:32 PM
ramabena
ramabena - avatar
+ 3
https://code.sololearn.com/ciIe19fPYB1w/?ref=app Sorry its in C# but hopefully it can help you. Good luck.
29th Oct 2017, 4:39 PM
WildGeese
WildGeese - avatar
+ 3
int main() int n,sum,sum1=0,i,j; printif("please enter a number"); scanf("%d",&n); for(i=1; i<=n,i++) sum=0 for(j=1;j<=i;j++); sum=sum+j sum1=sum1+sum;
19th Feb 2018, 11:08 AM
Mahnaz
Mahnaz - avatar