我正在尝试创建一个能够找到实数的力量的程序。问题是指数是十进制的,小于1但不是负数。
假设我们必须找到
的力量5 0.76
我真正尝试的是我写了0.76为76/100而且它是5 76/100 然后我写了
这是代码,如果你想看看我做了什么
public class Struct23 {
public static void main(String[] args) {
double x = 45;
int c=0;
StringBuffer y =new StringBuffer("0.23");
//checking whether the number is valid or not
for(int i =0;i<y.length();i++){
String subs = y.substring(i,i+1);
if(subs.equals(".")){
c=c+1;
}
}
if(c>1){
System.out.println("the input is wrong");
}
else{
String nep= y.delete(0, 2).toString();
double store = Double.parseDouble(nep);
int length = nep.length();
double rootnum = Math.pow(10, length);
double skit = power(x,store,rootnum);
System.out.println(skit);
}
}
static double power(double x,double store,double rootnum){
//to find the nth root of number
double number = Math.pow(x, 1/rootnum);
double power = Math.pow(number, store);
return power;
}
}
答案会来,但主要问题是我无法使用 pow 功能来做到这一点
我也不能使用 exp()和 log()功能。
i can only use
+
-
*
/
帮我建议你的想法。
提前致谢
答案 0 :(得分:4)
newtons_sqrt
我从https://stackoverflow.com/a/7710097/541038
中取回了大部分答案你也可以在newtons_nth_root
上解释给FormatDateTime('MM/dd/yyyy',ADOqueryname.fieldbyname('ModifiedDate').AsDateTime);
......但是你必须弄清楚0.76 == 76/100(我确实真的太难了)
答案 1 :(得分:2)
您可以将您的号码转换为其复杂形式,然后使用de Moivre' formula使用您的合法操作计算您号码的第n个根。