recur.cpp 386 B

12345678910111213141516171819
  1. // recur.cpp -- using recursion
  2. #include <iostream>
  3. void countdown(int n);
  4. int main()
  5. {
  6. countdown(4); // call the recursive function
  7. // std::cin.get();
  8. return 0;
  9. }
  10. void countdown(int n)
  11. {
  12. using namespace std;
  13. cout << "Counting down ... " << n << endl;
  14. if (n > 0)
  15. countdown(n-1); // function calls itself
  16. cout << n << ": Kaboom!\n";
  17. }