func abs(x: Float) -> Float:
{
if (x < 0)
{
return -x;
}
return x;
}
func GetSquareRootNewtonMethod(x: Float) -> Float:
{
var guess: Float = x / 2;
var next: Float = (guess + x / guess) / 2;
while (abs(next - guess) >= 0.01)
{
guess = next;
next = (guess + x / guess) / 2;
}
return next;
}
func main(argc: Int, argv: Array<String>):
{
var value: Float = 21.0;
print("Enter float value: ");
scan("%lf", value);
print("sqrt(%f) = %f", value, GetSquareRootNewtonMethod(value));
}
-
Notifications
You must be signed in to change notification settings - Fork 0
vstdio/Compiler
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Компилятор процедурного языка программирования
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published