Help with problem

This is a discussion on Help with problem within the C Programming forums, part of the General Programming Boards category; I'm just starting here, so please have a little patience with me. Here is the problem to start with. "Write ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    15

    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 10:30 PM.

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

    -Prelude
    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, 05: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, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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