/*将一整数逆序后放入一数组中(要求递归实现)*/ #include <cstdlib> #include <iostream> using namespace std; void revert(int *a, int index, int val) { if(val >= 10) revert(a, index + 1, val / 10); a[index] = val % 10; } int main(int argc, char *argv[]) { int a = 123456; int res[10]; memset(res, -1, 10 * sizeof(int)); revert(res, 0, a); for(int i=0; i<10; i++) if(res[i] >= 0) cout << res[i] << " "; cout << endl; system("PAUSE"); return EXIT_SUCCESS; } /*递归实现回文判断*/ #include <cstdlib> #include <iostream> using namespace std; int find(char *str, int n) { if(n <= 1) return 1; else if(str[0] == str[n - 1]) return find(str + 1, n - 2); else return 0; } int main(int argc, char *argv[]) { char *str = "googleelgoog"; if(find(str, strlen(str))) cout << "Yes" << endl; else cout << "N0" << endl; system("PAUSE"); return EXIT_SUCCESS; }