Python代码
def func(n,out=[]):
if n==1:
for i in "ATCG":
out.append(i)
print("".join(out))
out.pop(-1)
else:
for i in "ATCG":
out.append(i)
func(n-1,out)
out.pop(-1)
func(10)
C语言代码
#include <stdio.h>
char slast[10] = {'\0'};
char bp[4] = { 'A','T','C','G' };
int index = 0;
void testlast(int num, int index)
{
if (num > 0)
{
for (int i = 0; i <= 3; i++)
{
slast[index] = bp[i];
testlast(num - 1,index+1);
}
}
if (num == 0)
{
printf("%s\n", slast);
}
}
int main()
{
testlast(10, index);
}