解题思将输入数的每位数字保存下来,然后按要求输出;
注意事项:数组的界限问题。
参考代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n;
scanf("%d", &n);
int counts = 0;
int t = n;
while (t != 0)
{
counts++;
t = t / 10;
}
printf("%d\n", counts);
int *pt;
pt = (int *)malloc((counts)*sizeof(int));
for (int i = 0; i < counts; i++)
{
pt[i] = n % 10;
n = n / 10;
}
for (int i = counts-1; i >= 0; i--)
{
printf("%d ", pt[i]);
}
printf("\n");
for (int i = 0; i <= counts-1; i++)
{
printf("%d",pt[i]);
}
free(pt);
return 0;
}
0.0分
2 人评分