整个程序如下写。当然,你需要一个C++编绎器。不同编绎器对语法的承认不完全相同。比如main函数,有些允许void main(),我用的g++就不允许。
#include <iostream>
using namespace std;
int reverse (int n);
int main ()
{
int n;
cout<<"Please input a positive integer: ";
cin>>n;
cout<<"The reverse of "<<n<<" is "<<reverse(n)<<endl;
}
int reverse (int n)
{
if (n<0) return 0;
int b=1, index=0;
while (b<=n)
{b*=10;index++;}
int i,sum=0;
for (i=0;i<index;i++)
{
sum+=n%10;
sum*=10;
n/=10;
}
sum/=10;
return sum;
}
@稼