现在的位置: 首页 > 综合 > 正文

计算输入数字的个数

2017年10月27日 ⁄ 综合 ⁄ 共 243字 ⁄ 字号 评论关闭

这个功能很简单,就是竟然 一时想不到,在这里写一遍给新手一个素材(高手勿喷,如有错误,欢迎指正)

#include<iostream>
using namespace std;
int count(int input)
{
int output=0;
if(input==0)
return 1;
 while(input > 0)
{
input/=10;
 output++;
}
return output;
}
int main()
{
int input=0;
cin>>input;
cout<<count(input)<<endl;
}

抱歉!评论已关闭.