C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-10-2003, 05:19 PM   #1
Registered User
 
Join Date: Jul 2003
Posts: 21
i can't fix it! its driving me nuts

This is supposed to compute iMax^3 + iMax-1^3 + iMax-2^3...1^3
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   Reply With Quote
Old 07-10-2003, 05:41 PM   #2
+++ OK NO CARRIER
 
quzah's Avatar
 
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;
}
Try something like that. That should give you:

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   Reply With Quote
Old 07-10-2003, 05:46 PM   #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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 05:22 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22