IonicWind Snippit Manager 2.xx Released! Install it on a memory stick and take it with you! With or without IWBasic!
Started by GWS, December 04, 2019, 01:08:50 pm
0 Members and 2 Guests are viewing this topic.
' Square Root by Iteration ..openconsolecls' Calculating a Square Root using Iteration ..def x,y,z:doubledef i:intsetprecision 10print' Example:z = 27 :' positive real number whose Square root is requiredprintprint "Square Root of ",z:print:print STRING$(30, "_" )print:print:print "Iterations: ":printx = z/2 :' arbitrary start value for the iterationdo x = 0.5 * (x + z/x) print xuntil ((x*x - z)/z <= 1.e-11) :' the test for convergenceprintprint "The Square Root of ",z, " is ", x' Compare with the inbuilt Sqrt() function ..print:printprint "Using the CB Sqrt() Function, the result is .. ":printprint sqrt(z)print:print STRING$(30, "_" )do:until inkey$<>""closeconsoleend