C 练习实例27

C语言教程评论

C 练习实例27

题目:利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来。

程序分析:无。文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili27.html

实例

#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);
    }
}

以上实例输出结果为:文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili27.html

请输入5个字符 : abcde
相反顺序输出结果 : edcba
文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili27.html文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili27.html
运营不易,
感谢支持!
weinxin
我的微信
我的微信公众号
我的微信公众号扫一扫
weinxin
我的公众号
 最后更新:2021-12-7
公式库网
  • 本文由 公式库网 发表于 2021年12月6日20:11:24
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202112/c-lianxishili27.html

发表评论