1.0版.将个,十,百,千都表示出来
#include <stdio.h>
int main()
{
int input = 0;
scanf("%d",&input);
int a=input/1000;
int b=input%1000/100;
int c=input%1000%100/10;
int d=input%1000%100%10;
int output = a+b*10+c*100+d*1000;
printf("%d",output);
}
在这里遇到问题 输入1000,正确输出结果应为0001,实际输出为1,考虑不完善
2.0版.
用while写
#include <stdio.h>
int main()
{
int input = 0;
int output=0;
scanf("%d",&input);
while(input)
{
output=input%10+output*10;
input/=10;
}
printf("%d",output);
}
遇到了1.0版相同的错误
3.0版,用while和数组写
#include <stdio.h>
int main()
{
int input = 0;
int k =0;
int arr[50];
scanf("%d",&input);
while(input)
{
arr[k++]=input%10;
input/=10;
}
for(int i =0;i<k;i++)
{
printf("%d",arr[i]);
}
}
注意点:
1.k++最后一次是5,for循环内应i<k或者i<=k-1
2.while循环中的input应该改变,否则出现死循环
3,数组的[ ]内不能是变量
4.0版
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
while(n)
{
printf("%d",n%10);
n/=10;
}
return 0;
}