用递归算法实现如下题目(注:不用for,即算法中不用到for循环,提示用双重递归算法)
收起
知与谁同
2018-07-22 12:05:40
1883
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
-
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