![]() |
| | #1 |
| Registered User Join Date: Jul 2003
Posts: 21
| i can't fix it! its driving me nuts Instead, it doesn't . How can i add up the terms in my for loop? It is setup so it only adds iMax^3 and iMax-1^3, but i don't know how to fix it.#include <stdio.h> #include <math.h> void cube(void); int main(void) { cube(); return 0; } void cube(void) { int iMax, iAns, iCube, iNumber; printf("input max integer: "); scanf("%i", &iMax); iAns = pow(iMax,3); for (iNumber=1; iNumber <iMax; iNumber++) iCube = pow(iNumber,3) + pow(iMax,3); printf("Cube is : %i", iCube); } |
| faxtoaster is offline | |
| | #2 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,639
| 1) Stop spamming the board. Use your existing thread. 2) Use code tags. See left if you don't know how. 3) Why are you using the power function? Code: int cubethis( int tc )
{
return tc * tc * tc;
}
int foo( int f )
{
int x,y=0;
for( x = f; x > 0; x-- )
y += cubethis( x );
return y;
}
x = foo( 5 ); x = 5^3 + 4^3 + 2^3 + 1^3; Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #3 |
| Registered User Join Date: Jul 2003
Posts: 21
| thanks for the help, i'll see if that works. sorry for spamming the board i'm new at this. |
| faxtoaster is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting an error with OpenGL: collect2: ld returned 1 exit status | Lorgon Jortle | C++ Programming | 6 | 05-08-2009 08:18 PM |
| An error is driving me nuts! | ulillillia | C Programming | 5 | 04-04-2009 09:15 PM |
| This is driving me nuts. | Matt13 | C Programming | 3 | 03-25-2004 10:55 AM |
| This compiler is driving me nuts | martin_00 | C Programming | 32 | 12-31-2002 03:25 PM |
| driving me nuts | boontune | C++ Programming | 3 | 10-07-2002 04:35 AM |