Hi, new to the forum but I have read and understand u guys aren't here to do this for me and I know that and want to learn how to do this.
My goal is to write a program that to compute the following sum: 1+2*3+3*4*5+4*5*6*7+5*6*7*8*9+6*7*8*9*10*11+...+n* (n+1)*(n+2)*...*(2n-1)
Now me and some people figured this to be the same thing as
(2n-1)!/(n-1)!
here is what I have come up with so far but I am sure it's not correct any tips, suggestions, or constructive criticism is welcomed.
Code:
#include <iostream>
using namespace std;
int main()
{
int k, n, total=0, sum=0;
cout << "Enter a whole number: \n";
cin >> n;
k = n;
while (n>=1)
{
while (k<=2*n-1)
{
sum = k * ++k;
}
total= total+sum;
k = --n;
--n;
}
cout << "The answer to the equation for your number is ";
cout << total << endl;
return 0;
}
I know this isnt right b/c if n = 3 the answer output from the program should be 67 b/c
(5!/2!) + (3!/1!) + (1!/0!) = 67 but I get 72 when I run the program.
Thanks and sorry for the long post, me and my friends are just noobs trying to learn from mistakes.