计算位数

首先,我们得知道一定定理,如果10的n次方,那这个n就是多少位,对不对!对,这就很秒了

比如如果求一个N的数,N=10的log10N的次方,那么它的位数就是log10 N,流弊!!

有人说log10 怎么打?很简单c++的库函数里面有

log10(100)的返回值就是2,log(999)的返回值是二点几,不过如果你把返回值定位int型它就会自动转换成2了。

10的n次方的位数为n+1;

#include<iostream>
#include<cmath>

using namespace std;

int main(){
    int a,b;
    while(cin>>a>>b){
        a=log10(a+b)+1;
        cout<<a<<endl;
    }    
    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/shuaihui520/p/8982504.html