给出一系列期刊数字 例X = 3
x = 3的期刊系列必须如下所示
1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3
1 3 1
1 3 2
1 3 3
2 1 1
2 1 2
2 1 3
2 2 1
2 2 2
2 2 3
2 3 1
2 3 2
2 3 3
3 1 1
3 1 2
3 1 3
3 2 1
3 2 2
3 2 3
3 3 1
3 3 2
3 3 3
通缉:用C编写一个程序来打印这个系列 给定:假设x的最大值可以是10
我试着从想法开始..但都失败了.. 请帮忙 。谢谢:))
答案 0 :(得分:1)
def yourFunction(n, x):
recursiveFunction(n, x, 0, [0]*n)
def recursiveFunction(depth, breadth, currentDepth, indexes):
if currentDepth >= depth:
print indexes
else:
for indexes[currentDepth] in range(0, breadth):
recursiveFunction(depth, breadth, currentDepth + 1, indexes)
答案 1 :(得分:0)
#include<stdio.h>
#include<stdlib.h>
int printSeries(int list[], int max, int level){
if(level == max){
int i;
for(i=0;i<max;++i)
printf("%d ", list[i]);
printf("\n");
return 1;
}
while(list[level]<=max){
list[level]+=printSeries(list, max, level+1);
}
list[level] = 1;
return 1;
}
void printSeriesStart(int x){
int i, *list = malloc(x*sizeof(int));
for(i=0;i<x;++i){
list[i]=1;
}
printSeries(list, x, 0);
free(list);
}
int main(void){
int X = 3;
printSeriesStart(X);
return 0;
}