3.12 给出一个不多于5位的正整数,要求:1. 求出它是几位数;2. 分别打印出每一位数字;3. 按逆序打印出各位数字,例如原数位321,应输出123。

答案:

#include <iostream>
using namespace std;
int main()
{
	int num,s,sum=0,count=0;
    cout<<"Please input num:";
    cin>>num;
	cout<<"the  num is "<<num<<endl;
	if(num<0||num>100000)
	{
	cout<<"The entered num is wrong. Please enter a num in the range of 0-100000";
	}
	else
	{
	while(num!=0)
	{
	s=num%10;
	num=num/10;
    sum=sum*10+s;
	count++;
	cout<<"The order of each is "<<s<<endl;
	}
	
    cout<<"the reverse num is "<<sum<<endl;
    cout<<"the num have "<<count<<endl;
	}
	cout<<endl;
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值