解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <stdlib.h>
/*
给出一个不多于5位的整数,要求 1、求出它是几位数 2、
分别输出每一位数字 3、按逆序输出各位数字,
例如原数为321,应输出123
*/
int main(){
int num,count=0,r=0,t1,t2;
//char s[6]; //注意结束符
scanf("%d",&num);
//printf("%d",);
t2=num;
while(t2!=0){ //先求逆序数和位数
t1=t2%10;
r=r*10+t1;
t2/=10;
count++;
}
//再做输出
printf("%d\n",count);
t1=r;
while(t1!=0){
count--;
t2=t1%10;
t1/=10;
printf("%d",t2);
if(count>0)
putchar(' ');
}
putchar('\n');
printf("%d\n",r);
return 0;
}
0.0分
0 人评分
C二级辅导-进制转换 (C语言代码)浏览:615 |
C语言训练-求矩阵的两对角线上的元素之和 (C语言代码)浏览:602 |
C语言训练-立方和不等式 (C语言代码)浏览:751 |
C语言训练-角谷猜想 (C语言代码)浏览:1705 |
C语言程序设计教程(第三版)课后习题9.1 (Java代码)浏览:471 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:672 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:600 |
校门外的树 (C语言代码)浏览:961 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:648 |
P1000 (C语言代码)浏览:877 |