c语言编程中,怎样输入一个三位数,将其各位数字反序输出,如输入321,输出123。

如题所述

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>
using namespace std;
int main(){
int n;
cin>>n;
while(n!=0){
cout<<n%10;
n/=10;
}
cout<<endl;
return 0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-22
这个很简单,用字符串最简单
char a[10];
gets(a);
puts(strrev(a));

你要是不用数组,也能解决
int a,s=0;
scan("%d",&a);
while(a)
{
s=s*10+a/10;
a/=10;
}
printf("%d",s);本回答被网友采纳
第2个回答  2013-09-22
#include <stdio.h>

int main (int argc, char *argv[])
{
int n,reverse_n = 0;
int flag = 0;//标识位
scanf("%d",&n);
if(n < 0)
{
n = -n;
flag = 1;
}
while(n)
{
reverse_n = reverse_n*10 + n%10;
n = n / 10;
}
if(1 == flag)//处理负数
printf("-");
printf("%d\n",reverse_n);
return 0;
}
第3个回答  2013-09-22
#include<stdio.h>
void main(){
    int x,b;
    printf("Please input:");
    scanf("%d",&x);
    b=x%10*100+x/100+(x%100)/10*10;
    printf("%d",b);
}

第4个回答  2013-09-22
#define count 3
char str[count+1]="321",re[count+1];

int i=0;
for(i=0;i<count;i++)
re[i]=str[count-i-1];