-
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.
-
Code:
for ( x = 0; x < n; x++ )
printf ( "%.f\n", pow ( k, x ) );
Be sure to include <math.h> for the pow() function.
-Prelude