zoukankan      html  css  js  c++  java
  • 数值的整数次方

    #include <iostream>
    #include <math.h>
    using namespace std;
    bool equalzero(double a,double b)
    {
        if((a-b<0.0000001)&&(a-b>-0.0000001))
            return true;
        else
            return  false;
    }
    double powerwithtwo(double base,int exp)
    {
        double result = 1.0;
        for(int i=0;i<exp;i++)
            result *= base;
        return result;
    }
    double power(double base,int exp)
    {
        if(equalzero(base,0.0))
            return 0;
        if(exp>0)
        {
            return powerwithtwo(base,exp);
        }
        if(exp==0)
            return 1;
        if(exp<0)
        {
            double result = powerwithtwo(base,-exp);
            return 1.0/result;
        }
    }
    int main()
    {
        cout<<power(0,0)<<endl;
        cout<<pow(0,0)<<endl;
        return 0;
    }
    

    零的零次方无意义,得零也行 得一也行
  • 相关阅读:
    五种Sublime text 3同时快速编辑多行内容
    update 更新某个字段自动加1
    oracle 一行记录被锁
    事件
    练习题1
    语法
    开始js
    js简述
    概述
    软连接
  • 原文地址:https://www.cnblogs.com/xiaofeiwang/p/3825006.html
Copyright © 2011-2022 走看看