C Exercise Example 27
100 cases of classic C language
Title: recursive function call, five characters are entered, printed out in reverse order.
Program Analysis: None.
Source Code:
// Created by www.w3big.com on 15/11/9. // Copyright © 2015年 本教程. All rights reserved. // #include <stdio.h> int main() { int i=5; void palin(int n); printf("请输入5个字符\40:\40"); palin(i); printf("\n"); } void palin(n) int n; { char next; if(n<=1) { next=getchar(); printf("相反顺序输出结果\40:\40"); putchar(next); } else { next=getchar(); palin(n-1); putchar(next); } }
The above example output is:
请输入5个字符 : abcde 相反顺序输出结果 : edcba