#include <stdio.h>
int main()
{
int x,i,n,k=0,ch[100]={0};
printf("n=");
scanf("%d",&n);
printf("%d\n",0);
for(i=1;i<=n;i++)
x=i;
while(x!=0)
ch[k]=x%3;
x=x/3;
k++;
}
for(x=k-1;x>=0;x--)
printf("%d",ch[x]);
ch[x]=0;
printf("\n");
k=0;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
#include <stdio.h>
int main()
{
int x,i,n,k=0,ch[100]={0};
printf("n=");
scanf("%d",&n);
printf("%d\n",0);
for(i=1;i<=n;i++)
{
x=i;
while(x!=0)
{
ch[k]=x%3;
x=x/3;
k++;
}
for(x=k-1;x>=0;x--)
{
printf("%d",ch[x]);
ch[x]=0;
}
printf("\n");
k=0;
}
return 0;
}