import java.util.*;
import java.lang.*;
import java.io.*;
class SinusApp
{
public static Double scanDouble
( Scanner in
) {
return ( ( in.hasNextDouble() ) ? in.nextDouble() : null );
}
public static double pow2( double x ) //вторая степень
{
return x*x;
}
public static void main
( String[] args
) {
// рабочие переменные
double x, e, d, r;
long n, nMax
= Long.
MAX_VALUE; // лимит числа итераций чтобы избежать бесконечного цикла
// ввод данных - аргумента функции и заданной погрешности
Scanner in
= new Scanner
(System.
in);
x = scanDouble( in );
e = scanDouble( in );
in.close();
for( d = 0, r = x, n = 2; n < nMax; n++ ) // основной цикл вычислений
{
r
= r
* ( 1 - pow2
( x
) / ( pow2
( n
- 1 ) * pow2
( Math.
PI ) ) ); if( Math.
abs( d
) <= Math.
abs( e
) ) break; }
// вывод результата
System.
out.
printf("sin(x) = %f\n",
Math.
sin( x
) ); System.
out.
printf("calculated sinus = %f\n", r
); System.
out.
printf("inaccuracy = %f\n", d
); System.
out.
printf("number of iterations: %d\n", n
);
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBTaW51c0FwcAp7CiAgIHB1YmxpYyBzdGF0aWMgRG91YmxlIHNjYW5Eb3VibGUoIFNjYW5uZXIgaW4gKQogICB7CgkgICByZXR1cm4gKCAoIGluLmhhc05leHREb3VibGUoKSApID8gaW4ubmV4dERvdWJsZSgpIDogbnVsbCApOwogICB9CiAgIAogICBwdWJsaWMgc3RhdGljIGRvdWJsZSBwb3cyKCBkb3VibGUgeCApIC8v0LLRgtC+0YDQsNGPINGB0YLQtdC/0LXQvdGMCiAgIHsKICAgICAgcmV0dXJuIHgqeDsKICAgfQogICAKICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oIFN0cmluZ1tdIGFyZ3MgKQogICB7CiAgICAgIC8vINGA0LDQsdC+0YfQuNC1INC/0LXRgNC10LzQtdC90L3Ri9C1CiAgICAgIGRvdWJsZSB4LCBlLCBkLCByOwogICAgICBsb25nIG4sIG5NYXggPSBMb25nLk1BWF9WQUxVRTsgLy8g0LvQuNC80LjRgiDRh9C40YHQu9CwINC40YLQtdGA0LDRhtC40Lkg0YfRgtC+0LHRiyDQuNC30LHQtdC20LDRgtGMINCx0LXRgdC60L7QvdC10YfQvdC+0LPQviDRhtC40LrQu9CwCiAgICAgCiAgICAgCiAgICAgIC8vINCy0LLQvtC0INC00LDQvdC90YvRhSAtINCw0YDQs9GD0LzQtdC90YLQsCDRhNGD0L3QutGG0LjQuCDQuCDQt9Cw0LTQsNC90L3QvtC5INC/0L7Qs9GA0LXRiNC90L7RgdGC0LgKICAgICAgU2Nhbm5lciBpbiA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CiAgICAgIAogICAgICB4ID0gc2NhbkRvdWJsZSggaW4gKTsKICAgICAgZSA9IHNjYW5Eb3VibGUoIGluICk7CiAgIAogICAgICBpbi5jbG9zZSgpOyAKICAgCiAgICAgIGZvciggZCA9IDAsIHIgPSB4LCBuID0gMjsgbiA8IG5NYXg7IG4rKyApIC8vINC+0YHQvdC+0LLQvdC+0Lkg0YbQuNC60Lsg0LLRi9GH0LjRgdC70LXQvdC40LkKICAgICAgewogICAgICAgICByID0gciAqICggMSAtIHBvdzIoIHggKSAvICggcG93MiggbiAtIDEgKSAqIHBvdzIoIE1hdGguUEkgKSApICk7CiAgICAgICAgIGQgPSBNYXRoLnNpbiggeCApIC0gciA7ICAKICAgICAgICAgaWYoIE1hdGguYWJzKCBkICkgPD0gTWF0aC5hYnMoIGUgKSApIGJyZWFrOwogICAgICB9ICAgICAgCiAgICAgIAogICAgICAvLyDQstGL0LLQvtC0INGA0LXQt9GD0LvRjNGC0LDRgtCwCiAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCJzaW4oeCkgPSAlZlxuIiwgTWF0aC5zaW4oIHggKSApOwogICAgICBTeXN0ZW0ub3V0LnByaW50ZigiY2FsY3VsYXRlZCBzaW51cyA9ICVmXG4iLCByICk7CiAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCJpbmFjY3VyYWN5ID0gJWZcbiIsIGQgKTsKICAgICAgU3lzdGVtLm91dC5wcmludGYoIm51bWJlciBvZiBpdGVyYXRpb25zOiAlZFxuIiwgbiApOwoKICAgfQp9Cg==