More recursive, ugh!!

This is a discussion on More recursive, ugh!! within the C++ Programming forums, part of the General Programming Boards category; Does the following recurrence relation = 50, am I doing this right? Code: S(1)=5; S(N)=S(N-1) + 5 for N>1...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    40

    More recursive, ugh!!

    Does the following recurrence relation = 50, am I doing this right?

    Code:
    S(1)=5; S(N)=S(N-1) + 5 for N>1

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,702
    A recurrence relation itself doesn't equal some number...
    Code:
    #include <iostream>
    using namespace std;
    
    int S(int n)
    {
        if (n == 1)
            return 5;
    
        return S(n - 1) + 5;
    }//S
    
    int main()
    {
        for (int n = 1; n <= 10; n++)
            cout << "S(" << n << ") = " << S(n) << endl;
    
        return 0;
    }//main
    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. recursive function
    By technosavvy in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 05:42 AM
  2. difference between recursive and iterative
    By Micko in forum C Programming
    Replies: 33
    Last Post: 07-06-2004, 10:34 PM
  3. Algorithm help (Changing from Recursive to Non Recursive)
    By Thantos in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2004, 08:27 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 09:15 AM

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