readln(eps); writeln;
n:=0; x:=x0;
2: fx:=x*x-x-1;
f1x:=2*x-1;
y:=fx/f1x;
n:=n+1;
x:=x-y; textcolor(13);
if abs(y)>eps then goto 2;
writeln(‘yaqinlashishlar soni n=’ ,n);
writeln(‘taqribiy ildiz x=’ ,x:3:4);
end.
Ushbu dasturni kompyuterga kiritib natijalar olinganda x2-x-1=0 tenglamaning x0=b=2,5 boshlangich nuqtadagi va =0,0001 aniqlikdagi ildizi х=1,6180 ekanligiga eshonch hosil qilish mumkin. Buni esa berilgan chizmadan ham ko’rish mumkin.
Topshiriqlar:
1. Quyidagicha aniqlanadigan ketma-ketlik berilgan:
F0=F1=F2=1, Fi=Fi-3+Fi-2+Fi-1(i>2).
Bu ketma-ketlikning n-hadini topuvchi dastur tuzing.(0<=n<=40)
fun main() {
print("n kiriting: ")
val n = Scanner(System.`in`).nextInt()
val list = ArrayList()
list.add(1)
list.add(1)
list.add(1)
for (i in 3..40){
val f = list[i-3]+list[i-2]+list[i-1]
list.add(f)
if (i == n){
println("$n - xadi: ${list[i]}")
break
}
}
}
Dostları ilə paylaş: |