u012441335 于 2013.11.03 15:34 提问

C++实验的问题，求解答，急急急！！！

#include
using namespace std;
int main ()
{
int a,b,c,d,e,m,n;
cout << "请输入一个不多于五位的正整数:" << endl;
cin >> n;
if (n>=0&&n<=99999)
if (n<=9) cout << "这是一个一位数\n" << "个位数是:" << n << "逆向输出为:" << n <<endl;
else
{
if (n<=99)
a=n/10;
b=n-a*10;
m=b*10+a;
cout << "这是一个两位数\n" << "十位数是:" << a << "个位数是:" << b << "逆向输出为:" << m << endl;
}
else
{
if (n<=999)
{
a=n/100;
b=n/10-a*10;
c=n-a*100-b*10;
m=a+b*10+c*100;
cout << "这是一个三位数\n" << "百位数是:" << a << "十位数是:" << b << "个位数是:" << c << "逆向输出为:" << m << endl;
}
if (n<=9999)
{
a=n/1000;
b=n/100-a*10;
c=n/10-a*100-b*10;
d=n%10;
m=d*1000+c*100+b*10+a;
cout << "这是一个四位数\n" << "千位数是:" << a << "百位数是:" << b << "十位数是:" << c << "个位数是:" << d << "逆向输出为:" << m << endl;
}
if (n<=99999)
{
a=n/10000;
b=n/1000-a*10;
c=n/100-a*100-b*10;
d=n/100-a*100-b*10-c;
e=n%10000;
m=e*10000+d*1000+c*100+b*10+a;
cout << "这是一个五位数\n" << "万位数是:" << a << "千位数是:" << b << "百位数是:" << c << "十位数是:" << d << "个位数是:" << e << "逆向输出为:" << m << endl;

``````    }
}
``````

}

2个回答

u010013028   2013.11.03 16:07

#include
using namespace std;
int main ()
{
int a,b,c,d,e,m,n;
cout << "请输入一个不多于五位的正整数:" << endl;
cin >> n;
if (n>=0&&n<=99999)
if (n<=9) cout << "这是一个一位数\n" << "个位数是:" << n << "逆向输出为:" << n < if (n9)
{
a=n/10;
b=n-a*10;
m=b*10+a;
cout << "这是一个两位数\n" << "十位数是:" << a << "个位数是:" << b << "逆向输出为:" << m << endl;
}
if (n<=999&&n>99)
{
a=n/100;
b=n/10-a*10;
c=n-a*100-b*10;
m=a+b*10+c*100;
cout << "这是一个三位数\n" << "百位数是:" << a << "十位数是:" << b << "个位数是:" << c << "逆向输出为:" << m << endl;
}
if (n<=9999&&n>999)
{
a=n/1000;
b=n/100-a*10;
c=n/10-a*100-b*10;
d=n%10;
m=d*1000+c*100+b*10+a;
cout << "这是一个四位数\n" << "千位数是:" << a << "百位数是:" << b << "十位数是:" << c << "个位数是:" << d << "逆向输出为:" << m << endl;
}
if (n<=99999&n>9999)
{
a=n/10000;
b=n/1000-a*10;
c=n/100-a*100-b*10;
d=n/100-a*100-b*10-c;
e=n%10000;
m=e*10000+d*1000+c*100+b*10+a;
cout << "这是一个五位数\n" << "万位数是:" << a << "千位数是:" << b << "百位数是:" << c << "十位数是:" << d << "个位数是:" << e << "逆向输出为:" << m << endl;
}
}

u012441335 还是不行啊
4 年多之前 回复
u012555162   2013.11.03 21:27

u012441335 不是0~100000吗？？？
4 年多之前 回复