u

Friday 14 September 2012

C++ Program to implement a Recursive Function

C++ Program to implement a Recursive Function


 #include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
void recurfunc(int start,int stop,char* buff);
void main()


    {   clrscr();
    cout << "enter how many times to loop: ";
    char buff[100];
    cin >> buff;
    int num;
    num = atoi(buff);
    if(num >= 1)


        {
            recurfunc(0,num," this is a recursive function");
        }
        else


        {
            cout << "sorry you didnt enter valid data" << endl;
            return;
        }
        getch();
    }
    void recurfunc(int start,int stop,char* buff)


        {
        if(start < stop)


            {
                start++;
                cout << "\n" << buff << "\n";
                recurfunc(start,stop,buff);
            }
            else


            {
                return;
            }
        }

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More