加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C中的递归和printf

发布时间:2020-12-16 09:39:50 所属栏目:百科 来源:网络整理
导读:我的教授让我这样做: Input Number: 5+++++++++++++++++++++++++ 我一直在努力想要得到这个;我不停地用一个带有巨大空白的“”结尾 “”. 你能帮我修一下C代码吗? #include stdio.h#include conio.hint space(int space1){ if(space1 == 0) { return 1; }
我的教授让我这样做:

Input Number: 5
+++++
+++++
+++++
+++++
+++++

我一直在努力想要得到这个;我不停地用一个带有巨大空白的“”结尾
“”.

你能帮我修一下C代码吗?

#include <stdio.h>
#include <conio.h>
int space(int space1)
{
    if(space1 == 0)
    {
        return 1;
    }
    else
    {
        return printf("n") && space(space1 - 1);
    }
}
int visual(int plus)
{
    if (plus == 0)
    {
        return 1;
    }
    else
    {
        return printf("+") && visual (plus - 1) && space(plus - 1);
    }
}

int main()
{
    int number;
    printf("Please give the numbern");
    scanf("%d",&number);
    visual(number);
    getch();
}

一个新的编辑;让我很沮丧.它给了我5行和一个大空间.

解决方法

完整解决方案更新无循环:::

#include <stdio.h>
#include <conio.h>
int space(int space1)
{
    if(space1 == 0)
    {
        return 1;
    }
    else
    {
        return printf("+") && space(space1 - 1);
    }
}
int visual(int plus,int add)
{
    if (plus == 0)
    {
        return 1;
    }
    else
    {
        space(add);
        printf("n");
        visual (plus - 1,add);
    }

}

int main()
{
    int number,i;
    printf("Please give the numbern");
    scanf("%d",&number);

    visual(number,number);

    getch();
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读