Nested loops using recursion in python
##coder @ shivamzaz#demo in c++ in simple loops
'''for(i=0;i<n;i++){
for(j=0;j<nj++){
cout<<n<<endl;
}
}'''
def s_s(n):
i=0
s_f(i,n)
def s_f(i,n):
if(i<n):
j=0
s_g(i,j,n)
s_f(i+1,n)
def s_g(i,j,n):
if(j<n):
print i,j
s_g(i,j+1,n)
s_s(4)
##coder @ shivamzaz#demo in c++ in simple loops
for(j=0;j<nj++){
cout<<n<<endl;
}
}'''
def s_s(n):
i=0
s_f(i,n)
def s_f(i,n):
if(i<n):
j=0
s_g(i,j,n)
s_f(i+1,n)
def s_g(i,j,n):
if(j<n):
print i,j
s_g(i,j+1,n)
s_s(4)
No comments:
Post a Comment