c++编程,输入一个8位正整数,输出其逆序数,如输入12345678,输出87654321
#include <iostream>
using namespace std;
int main()
{
char number[10] = {0};
cin >> number;
char *low, *high;
low = number;high = number;
while(high && *high && high++);
high--;
while(high > low)
{
char tmp = *low;
*low = *high;
*high = tmp;
high--;low++;
}
cout << str <<endl;
}
可以用数组存储数据
温馨提示:内容为网友见解,仅供参考
第1个回答 2017-05-19
#include <iostream>
using namespace std;
int main()
{
int num;
cin>>num;
while(num!=0)
{
cout<<num%10;
num/=10;
}
return 0;
}
//思路就是每次输出取余运算的结果,再把整个数除以10来扔掉最后一位数,重复输出就好了
Warning: Invalid argument supplied for foreach() in /www/wwwroot/aolonic.com/skin/templets/default/contents.html on line 45
相似回答