#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; }
零的零次方无意义,得零也行 得一也行