解题思将输入数的每位数字保存下来,然后按要求输出;
注意事项:数组的界限问题。
参考代码:
#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语言代码)浏览:767 |
C语言程序设计教程(第三版)课后习题8.3 (Java代码)浏览:1372 |
大神老白 (C语言代码)浏览:611 |
简单的a+b (C语言代码)浏览:542 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:623 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:763 |
C语言训练-大、小写问题 (C语言代码)浏览:613 |
简单的a+b (C语言代码)浏览:579 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:407 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:604 |