设计一个c++程序,输入一个4位数,将其反序输出.例如1234,输出4321.

来源:百度知道 编辑:UC知道 时间:2024/05/09 16:36:10

#include <iostream>
using namespace std;
int reve_int(int n){
int t=0;
while(n){
t*=10;
t+=n%10;
n/=10;
}
return t;
}

void main(){
int n;
cin>>n;
cout<<"\n"<<reve_int(n)<<endl;
}

#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "请输入4位数:";
string instr;
cin >> instr;
string outstr;
for (int i=0; i<4; ++i)
{
outstr += instr[4-i-1];
}
cout << "反序输出:" << outstr << endl;
}
附:
删掉你的"for(n=1000;n<10000;n++)"那行
否则输入要循环9000次

#include<iostream.h>
#include<string.h>
void main()
{
char number[4];
cout<<"input the numbers: "<<endl;
for(int i=0;i<