2012/01/05 10:46:10

То же, но в комменте:

Link
2012/01/05 10:46:41

Так. Код в комментах не работает. Не порядок!

Link
2012/01/05 10:54:02


define method newtons-sqrt (x :: )
local method sqrt1 (guess)
// note call to other local method
if (close-enough? (guess))
guess
else
sqrt1 (improve (guess)) // note self-recursive call
end if
end sqrt1,
method close-enough? (guess)
abs (guess * guess - x) < .0001
end close-enough?,
method improve (guess)
(guess + (x / guess)) / 2
end improve;
sqrt1 (1)
end method newtons-sqrt;

Link
2012/01/05 10:56:38

#include <iostream>

bool zoo(int c)
{
int z = c;
int step = 1;

bool r = (
step = 1,
z--,
std::cout << "step 1: " << z << std::endl,
z > 0 ) and (
step = 2,
z-- ,
std::cout << "step 2: " << z << std::endl,
z > 0 ) and (
step = 3,
z--,
std::cout << "step 3: " << z << std::endl,
z > 0 ) and (
z = z*z,
std::cout << "Ending... " << z << std::endl,
true ) or (
std::cout << "Error on step " << step << std::endl,
false );

return r;
}

int main()
{
zoo(4);
zoo(3);
zoo(2);
zoo(1);
zoo(0);
}

Link