首页 > 其他 > 详细

编程之美Q1

时间:2019-11-04 14:17:34      阅读:64      评论:0      收藏:0      [点我收藏+]

题目

技术分享图片

 

 和数书页有点类似,就直接数吧

#include<iostream>
using namespace std;
class q1
{
	public:
		size_t func(size_t num);
};
size_t q1::func(size_t num)
{
	size_t count = 0, tmp;
	while(num)
	{	
		tmp = num;
		while(tmp)
		{
			if(tmp%10 == 1)
				++count;
			tmp = tmp/10;
		}
		--num;
	}
	return count;
}

int main()
{
	q1 an;
	size_t num = 0;
	while(1)
	{
	cout<<"please input positive integer: ";
	cin>>num;
	cout<<num<<" to 0 include "<<an.func(num)<<" number 1 ."<<endl;
	}
	//num = 0xffffffff;
	//cout<<num<<" to 0 include "<<an.func(num)<<" number 1 ."<<endl;
}

 可循环输入,运行效果

技术分享图片

 

 问题2

 

编程之美Q1

原文:https://www.cnblogs.com/area-h-p/p/11791337.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!