Skip to content

Latest commit

 

History

History
33 lines (30 loc) · 567 Bytes

README.md

File metadata and controls

33 lines (30 loc) · 567 Bytes

compiler-60min

Пример кода на языке

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));
}