Friday, July 31, 2009

Summation notaion in c++?

update, i have this sum2 = n^2(n+1)^2 then the entire thing divided by 4





this is what i have so far, the first part of the program is ok, cause i have to compare this two.


// Program prog3d.cpp:


// print the sum of first n cubes in four ways and


// compare sum1 and sum2


// compare sum2 and sum3


// compare sum3 and sum4


#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;


using namespace std;


int integer;


int letter;


int main ()


{


int i, n, sum1 = 0, sum2;





for (i = 1; i %26lt;=n; i++) {


sum1 = sum1 + i*i*i;


}


cout %26lt;%26lt; sum1 %26lt;%26lt; endl;





for ( ; i %26lt;= n; ) {


sum2 = n * n ( n + 1)(n + 1) / 4;


}


cout %26lt;%26lt; sum2 %26lt;%26lt; endl;








system ("PAUSE");





return 0;


}





this line is my problem : sum2 = n *n ( n + 1)(n + 1) / 4;


its telling me that n is not a function, but i know that i can declare a letter n, because in the end of everything i have to assign n and number.





plz help

Summation notaion in c++?
You forgot to put an asterisk sign after the second "n" and after the first closing bracket.





sum2 = n *n* ( n + 1)*(n + 1) / 4;


No comments:

Post a Comment