Thread: Recursion

  1. #1
    Registered User
    Join Date
    May 2002


    I have a exercise which asks that a function be writen that returns the value of base and exponent using recursive function.
    for example; integerpower (3,4) = 3*3*3*3. Assume that the exponent is a positive nonzero integer, and base is an integer. The function should use for to control the calculation. Can you explain what the original call code will make this work?

  2. #2
    Please restate your question. I find that a lot of people post questions about programming, but should really be learning to write english instead.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    I think you want something more like this:
    /* Recursive factorial function */
    #include <stdio.h>
    long integerpower (int base, int exponent);
    int main()
      int  x, y = 2;
      for ( x = 1; x <= 10; x++ )
        printf ("%d^%d\tis %d\n", y, x, integerpower ( y, x ) );
      return 0;
    long integerpower (int base, int exponent)
      if (exponent == 1)
        return base;
        return(base * integerpower(base, exponent -1));
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template Recursion Pickle
    By SevenThunders in forum C++ Programming
    Replies: 20
    Last Post: 02-05-2009, 09:45 PM
  2. convert Recursion to linear can it be done
    By umen242 in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2008, 02:58 AM
  3. Recursion... why?
    By swgh in forum C++ Programming
    Replies: 4
    Last Post: 06-09-2008, 09:37 AM
  4. a simple recursion question
    By tetra in forum C++ Programming
    Replies: 6
    Last Post: 10-27-2002, 10:56 AM
  5. To Recur(sion) or to Iterate?That is the question
    By jasrajva in forum C Programming
    Replies: 4
    Last Post: 11-07-2001, 09:24 AM