Thread: Help with problem

  1. #1
    Registered User
    Join Date
    Apr 2002

    Question Help with problem

    I'm just starting here, so please have a little patience with me. Here is the problem to start with.

    "Write a program that reads in two numbers, n and k, from the data, then computes the sum of the first n powers of k. For example, if k is 2, it computes the sum of the first n squares, but if k is 3, it computes the sum of the first n cubes. Is there a simple check for this problem."

    I've been practicing with sums of first numbers with steady exponents ex. sum of first n cubes or squares etc. I am hitting a wall on how to find the sums when the exponent varies. I tried some nested for loops and this damn book isn't getting me anywhere. Any links to tutorials etc. would be great or help on what kind of loop to make.
    Last edited by brutal; 04-12-2002 at 09:30 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    for ( x = 0; x < n; x++ )
      printf ( "%.f\n", pow ( k, x ) );
    Be sure to include <math.h> for the pow() function.

    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM