C++ examples for Function:Recursive Function
Use recursive function to print array
#include <ctime> #include <iostream> void printArray(const int[], int, int); static const int LIMIT = 20; int main(int argc, const char *argv[]) { srand(time(0));/*from ww w . j av a2 s.c o m*/ int n[LIMIT]; for (int i = 0; i < LIMIT; ++i) { n[i] = rand() % 100 + 1; } printArray(n, 0, LIMIT); return 0; } void printArray(const int n[], int start, int end) { if (start >= end) return; std::cout << n[start] << std::endl; printArray(n, ++start, end); }