逆序输出int类型数字
#include<stdio.h>#include<stdlib.h>
unsigned int q(unsigned int x) //求出几位数字
{
unsigned int i = 1 , j = 10;
if(x < j)
printf("%d是%d位数字.\n",x,i);
else
{
while(x >= j)
{
j *= 10;
i++;
}
printf("%d是%d位数字.\n",x,i);
}
return i;
}
void m(unsigned int arr[],unsigned int j, unsigned int m) //分别输出每一位数字
{
int i;
unsigned int x = 10, y = 1;
for(i = j-1; i >= 0; i--)
{
arr[i] = m % x / y;
x *= 10;
y *= 10;
}
for(i = 0; i < j; i++)
{
printf("%d, ",arr[i]);
if((i + 1) % 5 == 0)
{
printf("\n");
}
}
printf("\n");
}
unsigned int tiao(unsigned int a[], unsigned int x) //按逆序输出各位数字
{
unsigned int b = 0 , c = 1;
for(int i = 0; i < x; i++)
{
b += a[i] * c;
c *= 10;
}
return b;
}
int main()
{
unsigned int x , y , z , e;
unsigned int ar[10] = {0};
printf("输入数字(0-1000000000) : ");
while((y = scanf("%d",&x)) != 1 || x < 0 || x > 1000000000)
{
if(y != 1)
scanf_s("%*s");
printf("请正确输入数字(0-1000000000) : ");
}
z = q(x);
m(ar,z,x);
e = tiao(ar,z);
printf("%d\n",e);
system("pause");
return 0;
}