开发者社区> 问答> 正文

用递归算法实现如下题目(注:不用for,即算法中不用到for循环,提示用双重递归算法)

12 23 3 3n. . . .n

展开
收起
知与谁同 2018-07-22 12:05:40 1803 0
4 条回答
写回答
取消 提交回答
  • 阿里云开发者社区运营负责人。原云栖社区负责人。
    myprintf( int n, int n1)
    {
    if( n>1 )
    myprintf( n-1,n1);
    printf( "%d",n1);
    }

    myfun( int n )
    {
    if( n > 1 )
    myfun( n-1 );
    myprintf( n, n );
    }
    2019-07-17 22:55:27
    赞同 展开评论 打赏
  • 社区管理员
    给你个javascript版的
    验证通过
    <script type="text/javascript">
    function f1(n)
    {
    if (n==0) return;
    f1(n-1);
    for (i=0;i<n;i++)
    {
    document.write(n);
    }
    document.write("<br/>");
    }
    f1(5)
    </script>
    2019-07-17 22:55:27
    赞同 展开评论 打赏
  • Nothing for nothing.
    pline(int now,int max)
    {
    printf("%d ",now++);
    if(now<=max)
    pline(now,max);
    }

    func(int n)
    {
    if(n>1)
    func(n-1);
    pline(1,n);
    printf("\n");
    }

    main()
    {
    int n=1;
    printf("Input n:");
    scanf("%d",&n);
    func(n);
    }

    turbo2.0测试通过
    2019-07-17 22:55:27
    赞同 展开评论 打赏
  • sorry,刚才那个还有for,这个没有for了
    js版
    <script type="text/javascript">
    function aa(x,y)
    {
    if (y==0) return;
    aa(x,y-1);
    document.write(x);
    }
    function a(x)
    {
    if (x==0) return;
    a(x-1);
    aa(x,x);
    document.write("<br/>");
    }
    a(8)
    </script>

    asp版
    <%

    sub aa(x,y)
    if y=0 then exit sub
    call aa(x,y-1)
    response.write x
    end sub
    sub a (x)
    if x=0 then exit sub
    call a(x-1)
    call aa(x,x)
    response.write "<br/>"
    end sub

    call a(8)

    %>
    2019-07-17 22:55:27
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
数据+算法定义新世界 立即下载
袋鼠云基于实时计算的反黄牛算法 立即下载
Alink:基于Apache Flink的算法平台 立即下载