Thread: Recursions

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Recursions

    Recursions seem to be a very very very confusing subject I know it is for me so I was wondering if someone was kind enough to give me an example of recursions, I mean the easiest one you can come up with, because for the time being I need the easiest example possible.
    Last edited by incognito; 11-27-2001 at 05:02 PM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    5

    here

    int example(int n){
    if (n==1) //must have base case to get out of recursion
    return (1); // base case, when n = 1, return value 1

    answer = example (n-1) * 2; //recursively decrement n, *2
    //when n = 1 it'll get out
    return (answer);
    }

    //non recursion of the same program
    int example2 (int n){
    int t, answer;

    answer = 1;

    for (t=1; t<= n; t++)
    answer = answer*t;

    return (answer);
    }

    //you can write every recursion NON-recursively, many times recursion is too much over head. But Easier to understanding.

    cycbersnaek

  3. #3
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Code:
    #include <iostream>
    
    using namespace std;
    
    void print(char *a)
    {
    
    	if(a[0]!=0)	
    	{	
    		cout << a[0];
    		print(++a);
    			
    	}
    
    	
    }
    
    int main()
    {
    	char rec[]="Recursion";
    	print(rec);
    
    	return 0; 
    }
    zen

  4. #4
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Thank you

    Thanks guys I believe I got it with your help
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what are RECURSIONS....???
    By ajayd in forum C Programming
    Replies: 4
    Last Post: 02-16-2008, 10:42 PM
  2. Recursions killing me
    By salvadoravi in forum C Programming
    Replies: 12
    Last Post: 01-29-2008, 04:48 AM
  3. Replies: 3
    Last Post: 11-17-2001, 09:16 AM
  4. Recursions....please help
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 11-15-2001, 01:54 PM
  5. need help with recursion's base case...
    By matheo917 in forum C++ Programming
    Replies: 8
    Last Post: 11-10-2001, 02:40 AM