编程:程序功能是对x=1,2,3,…,10,求f(x)=x*x-5*x+sin(x)的最小值

用while语句实现
2024-12-21 19:52:26
推荐回答(3个)
回答1:

public class ReadFile{
public static void main(String args[]){
double min = 99999999;
for(int i = 1; i < 10; i++){
double tem = Math.sin(i) + i * i - i * 5; //Math.sin(i)一定要放在前面,否则出错
min = tem < min ? tem : min;
}
System.out.println("最小值为: " + min);
}
}

回答2:

x := 1;
k := 0.0;
while x<11 do begin
if k > f(x) then k=f(x);
end;

回答3:

什么语言?matlab?