Recursion function is a function to call itself - C++ Function

C++ examples for Function:Recursive Function

Description

Recursion function is a function to call itself

Demo Code

#include <iostream>
using namespace std;
void removeHat(char cat) {
   for(char c = 'A'; c < cat; c++)
      cout << "  ";
   if(cat <= 'Z') {
      cout << "cat " << cat << endl;
      removeHat(cat + 1); // Recursive call
   } else/*w  ww .j  a  va 2  s.  c  o m*/
   cout << "Done" << endl;
}
int main() {
   removeHat('A');
}

Result


Related Tutorials