X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fbeginners.git;a=blobdiff_plain;f=pie_new.c;fp=pie_new.c;h=860c816407bbe35bc07852040d39adc3fd85a906;hp=0000000000000000000000000000000000000000;hb=62e4aa7ef68064df6c9c2d72734e21af2b672758;hpb=2473d40268a211cffc6bfbd8a19e66fce838c236 diff --git a/pie_new.c b/pie_new.c new file mode 100644 index 0000000..860c816 --- /dev/null +++ b/pie_new.c @@ -0,0 +1,63 @@ +#include +#include +#include + +int counter1; +// float counter3; +float counter2; +int steps; +int hits; +float x; +float x2; +float y; +float y2; +float pie; +float pie2; +char stepschar[100]; + +int main() +{ + + printf("\n"); + printf("\n"); + printf("Berechne Pie...\n"); + printf("\n"); + printf("Genauigkeit - [steps] ? : "); + + fgets(stepschar, sizeof(stepschar), stdin); + sscanf(stepschar, "%d", &steps); + + counter2 = 0; + hits = 0; + pie2 = 1; + + for (counter1 = 1; counter1 <= steps; ++counter1) + { + x = rand( ); + y = rand( ); + + x2 = x / RAND_MAX; + y2 = y / RAND_MAX; + + printf("%7d. Vektor: ( %f , %f )\n", counter1, x2, y2); + + if( ( x2 * x2 + y2 * y2) <= 1 ) + ++hits; + + // counter3 = counter1; + + pie2 = pie2 * ((float)(( 2 * counter1 ) * ( 2 * counter1 )) / (float)((( 2 * counter1 ) * ( 2 * counter1 )) - 1 )); + + counter2 = counter2 + x2 + y2; + } + + pie = (4.0 * hits) / steps; + pie2 = 2 * pie2; + + printf("\n"); + printf("\tPie :\t %1.8f\n", pie); + printf("\tProbe:\t %1.8f (nah an 0.5 ?...)\n\n", counter2 / ( 2.0 * steps )); + printf("\tAus Rekursion:\t %1.8f\n", pie2); + +return (0); +}