Advertisement

complicated math?

Started by March 16, 2004 09:06 AM
4 comments, last by dennizzz 20 years, 11 months ago
how do i get this math out to good c++ code? for example: in*Óranta^years where Ó go from x to y ??
More info is needed...

Is this a summation of the form a * b ^ c where b goes from x to y , which are integer values? If so, you can use the pow() function to calculate b ^ c , and a for loop to do the overall summation.


int Agony() { return *((int*)0); } Mwahaha... >8)
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Advertisement
yes this is a summation...

for example:

a* summation of (b)^n where n goes from x to y..

any nice example?
  int result;  for(int n=x;n<y;n++){    result=a*pow(b,n);  };
why not just use the formula for the summation of a geometric series
(1-r^n )/(1 - r)

this way you would have to use pow() at most 2 times.
in case want to use the loop & you want this:

"a* summation of (b)^n where n goes from x to y..."

don''t use penguins, use this...

    int sum = 0;    for( int n=x ; n <= y ; n++ ) {        sum += pow( b, n );    }    int result = a * sum; 


there are subtle differences : )

This topic is closed to new replies.

Advertisement