C语言编程:输入一个1以上的整数(任意位数) 实行此程序后输入的整数以逆序输出 例如 输入:123 输出:32

条件:使用while循环 并且用最简单的方式 不要用到for ,char。

望高手指教具体程序
(看到在此之前已经有数人提过类似问题 但那些回答里没有符合上面条件的...所以请不要将那些不符合本题条件的答案copy过来 thx)
标题更正→输入:123 输出:321

哥们试试这个:
main()
{
int n,rightDight, output=0;
printf("please input a number:");
scanf("%d",&n);
do
{
rightDight=n%10;
output=output*10+rightDight;
n=n/10;
}while(n!=0);
printf("the result is %d",output);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-10-22
#include<stdio.h>
#include<stdlib.h>

int main()
{
int n;
int *p1, *p2;
printf("请输入整数的位数:\n");
scanf("%d",&n);

p1 = p2 = (int *) malloc(n * sizeof(int));
printf("请输入整数:\n");
while(n)
{
scanf("%d",(p2++));
n--;
}
printf("\n换位后的数为:\n");
while(p2 != p1)
{
printf("%d",*(--p2));
}
printf("\n");
return 0;
}
///////////////////////////////////////////////
输入的时候每一位数用回车输入,不要连续输。
这个程序用char会更简单吧,while能做的事情for都能做,而且更简单。
第2个回答  2010-10-22
这是我自己编的
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int isrc;
int newInt=0;
int tmpSrc;
int nLen=1;
int *p=NULL;
cout<<"输入一个大于1的整数"<<endl;
cin>>isrc;
tmpSrc=isrc;
while ((tmpSrc=tmpSrc/10)>0)
{
nLen++;
}
p=new int[nLen];
int tmpLen=nLen;
int i=0;
tmpSrc=isrc;
while (tmpLen-->0)
{
p[i]=tmpSrc%10;//低位开始提取
tmpSrc=tmpSrc/10;

newInt+=pow(10,tmpLen)*p[i];
i++;
}

cout<<"原始整数:"<<isrc<<endl;
cout<<"新整数: "<<newInt<<endl;

if (p!=NULL)
{
delete []p;
p=NULL;
}
return 0 ;
}
第3个回答  2010-10-22
#include "stdio.h"
main()
{int a,b;
scanf("%d",&a);
printf("\n");
while(a!=0)
{printf("%d",a%10);
a=a/10;
}
}
第4个回答  2010-10-22
WIN-TC运行OK 自己写的哦 给我加分
#include <stdio.h>
main()
{int a,i;
scanf("%d",&a);
while(a>0)
{printf("%d",a%10);
a=a/10;
}
getch();
}
第5个回答  2010-10-22
int i;
x是你输入的正整数值.

i = 10;
while (x) {
pirntf("%d", x%i);
x /= i;
}
相似回答