解题思将输入数的每位数字保存下来,然后按要求输出;
注意事项:数组的界限问题。
参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:935 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:682 |
矩阵加法 (C语言代码)浏览:1719 |
模拟计算器 (C++代码)浏览:800 |
C二级辅导-计负均正 (C语言代码)浏览:480 |
大神老白 (C语言代码)浏览:600 |
理财计划 (C语言代码)浏览:465 |
陶陶摘苹果2 (C语言代码)浏览:595 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:984 |
小O的乘积 (C语言代码)浏览:1009 |