8
#include<stdio.h>
#include<math.h>
#define M 100
int main()
{
int num;
int i,j,r,k;
int count = 0;
int a[M],b[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
scanf("%d",&num);
num = (int)pow(3,num);
printf("num = %.0lf\n",num);
for(i = 1;i <= num; i++)
{
j = i;
while(j)
{
a[j] = b[r%3];
r = r/3;
j++;
}
for(k = 0;k < j; k++)
printf("%d",a[k]);
printf("\n");
}
}原文:http://blog.csdn.net/u010464679/article/details/41986031