Thread: Calculating Sums

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    21

    Question Calculating Sums

    I need to calculate a sum of cubes in one of my programs, but have no idea how to get started. I started using a For loop but have had lots of trouble getting results. I am asking the user to put in a maximum integer and i cube it, then i add the values before it cubed. Ie: a user enters 5 and i need to calculate 5^3 + 4^3 + 3^3 + 2^3 + 1^3. I don't know how to do this and its a pretty big part of my program. Thanks!

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    21

    still confused

    i know that i should be using a function, but i can't figure out the loop. i have it set up like this:

    for(iNumber =1; iNumber<iMax; iNumber++)
    iAns: pow(iMax,3) + pow(iNumber,3);
    printf("Sum of the cubes: blah blah blah);

    but i can only get the last number of the for loop in there, i need it to be iNumber1^3 + iNumber2^3, etc. is there a way to sum the numbers in my for loop? i am not good at this stuff.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164

    Re: still confused

    Code:
    TotVal = 0
    for(iNumber =1; iNumber<iMax; iNumber++)
    {
         TotVal += pow(iNumber,3);
    }
    printf("Sum of the cubes: blah blah blah);
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    21
    Thanks everybody, i got it working!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculating : high numbers
    By MiraX33 in forum C++ Programming
    Replies: 9
    Last Post: 06-08-2006, 11:08 PM
  2. Calculating CPU Usage
    By vitaliy in forum Linux Programming
    Replies: 3
    Last Post: 08-21-2005, 09:38 AM
  3. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 12:00 AM
  4. Taking input while calculating
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 07-12-2002, 04:47 PM
  5. Calculating window sizes
    By Mox in forum Windows Programming
    Replies: 3
    Last Post: 11-08-2001, 09:17 PM