1. 汉诺塔:#include<iostream> using namespace std; void hanoi(int n,char x,char y,char z); void move(int n,char theFirst,char theSecond); int main() { hanoi(4,'x','y','z'); getchar(); return 0; } void hanoi(int n,char x,char y,char z) { // //递归的基底 if(1==n) { move(1,x,z); } // //分解的步骤 else { hanoi(n-1,x,z,y); move(n,x,z); hanoi(n-1,y,x,z); } } void move(int n,char theFirst,char theSecond) { cout<<"move the "<<n<<" panel from "<<theFirst<<" to "<<theSecond<<endl; } 2. int型以字符输出:#include<stdio.h> void intToString(int intInput) { if(intInput<0) { printf("%c",'-'); intToString(intInput*(-1)); } else { // //递归的基底 if(intInput<10) { putchar('0'+intInput); } / //分解的步骤 else { intToString(intInput/10); putchar('0'+intInput%10); } } } int main() { intToString(-2953); getchar(); return 0; }