029(if的用法)

题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。

程序分析:学会分解出每一位数,如下解释:

程序源代码:

#include<iostream>
using namespace std;
int main()
{
	int num;
	int a,b,c,d,e;

	cin>>num;

	a=num/10000;
	b=num/1000%10;
	c=num/100%100%10;
	d=num%100/10;
	e=num%10;

	if(a!=0)
		cout<<e<<" "<<d<<" "<<c<<" "<<b<<" "<<a<<endl;
	else
		if(b!=0)
			cout<<e<<" "<<d<<" "<<c<<" "<<b<<endl;
		else
			if(c!=0)
				cout<<e<<" "<<d<<" "<<c<<endl;
			else
				if(d!=0)
					cout<<e<<" "<<d<<endl;
				else
					if(e!=0)
						cout<<e<<endl;
					else
						cout<<"输入为0:"<<endl;




	
	return 0;
}
	


你可能感兴趣的:(029(if的用法))