解题思路:

我的方法有点冗长(尴尬一笑)


注意事项:





参考代码:

#include<stdio.h>

#include<math.h>

int judge(int);

int main(void)

{

int num;

int i;

int array[5];

//printf("请输入一个不多于五位的数:\n");

scanf("%d",&num);

printf("%d\n",judge(num));


switch(judge(num))//根据位数输出

{

case 1:

printf("%d",num);

break;

case 2:

printf("%d %d",num/10,num%10);

break;

case 3:

printf("%d %d %d",num/10/10,num/10%10,num%10);

break;

case 4:

printf("%d %d %d %d",num/10/10/10,num/10/10%10,num/10%10,num%10);

break;

case 5:

printf("%d %d %d %d %d",num/10/10/10/10,num/10/10/10%10,num/10/10%10,num/10%10,num%10);

break;

}

switch(judge(num))

{

case 1:

printf("%d",num);

break;

case 2:

printf("\n%d%d",num%10,num/10);

break;

case 3:

printf("\n%d%d%d",num%10,num/10%10,num/10/10);

break;

case 4:

printf("\n%d%d%d%d",num%10,num/10%10,num/10/10%10,num/10/10/10);

break;

case 5:

printf("\n%d%d%d%d%d",num%10,num/10%10,num/10/10%10,num/10/10/10%10,num/10/10/10/10);

break;

}

}


int judge(int num)//判断位数

{

int count=0;

int i;

for(i=0;;i++)

{

//count++;

num=num/10;

count++;

if(num==0)

break;

}

return count;

}


 

0.0分

0 人评分

  评论区