Search:

Type: Posts; User: Red

Search: Search took 0.10 seconds.

  1. Replies
    9
    Views
    3,585

    Re: Sum of Powers using recursion

    yeap got it solved...


    public int sumPowTo (int n, int k)
    // Method for calculating sum of powers, which using the power method above
    {
    if ( n == 0) // Base case, if n equals to 0 the...
  2. Replies
    9
    Views
    3,585

    Re: Sum of Powers using recursion

    from the tracing that i have made is 1^2+2^2+3^2+4^2 = 30 [int (4,2)}
    or in other example 1^3+2^3+3^3+4^3+5^3 = 225 [int (5,3)]

    that i need help in detecting the hole in my program and the reason...
  3. Replies
    9
    Views
    3,585

    Re: Sum of Powers using recursion

    i did try using n-1 and k-1 but the outcome still the same. i trace my program on the paper before i wrote the program the outcome is 30..
  4. Replies
    9
    Views
    3,585

    Sum of Powers using recursion

    i got a little bit of problem with my coding for finding the total sum..

    the formula given to me is 1^k+2^k+...+n^k.
    my coding as follows:

    public int sumPowTo (int n, int k)
    {

    ...
Results 1 to 4 of 4