#include
int main()
{
int a;
printf("输入一个三位的正整数\n");
scanf("%d",&a);
if (a<=999&&a>99)
{ printf("三位数各位数字是:%d,%d,%d\n",a/100,(a%100)/10,(a%100)%10);
printf("按逆序输入是:%d%d%d\n",(a%100)%10,(a%100)/10,a/100);
}
else
printf("请输入正确数字\n");
return 0;
}
#include
int main()
{
int a,n,i,t;
int buf[5] = {0};
scanf("%d",&a);
if(a<0 || a > 99999)
{
printf("超出范围!\n");
return 0;
}
t = a;
n =0;
while (t > 0)
{
buf[n] = t % 10;
t = t / 10;
n++;
}
printf("%d位数!\n", n);
printf("各位数分别是:");
for(i=n-1; i>=0; i--)
{
printf("%d ", buf[i]);
}
printf("\n");
printf("逆序打印:");
for(i=0; i
printf("%d ", buf[i]);
}
printf("\n");
return 0;
}
***************************************************************************************************
num = 66358
num = 85366
逆序后,num = 66358
Press any key to continue
***************************************************************************************************
#include
int main() {
int i,n = 0,num;
char ch,s[20];
printf("num = ");
scanf("%d",&num);
while(num) {
s[n] = num%10 + '0';
num /= 10;
++n;
}
s[n] = '\0';
printf("num = %s\n",s);
for(i = 0; i < n/2; ++i) {
ch = s[i];
s[i] = s[n - i - 1];
s[n - i - 1] = ch;
}
printf("逆序后,num = %s\n",s);
return 0;
}