added string2hex prog (usefull for wep key)
[my-code/beginners.git] / pie_improved.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4
5 int counter1;
6 // float counter3;
7 float counter2;
8 int steps;
9 int hits;
10 float x;
11 float x2;
12 float y;
13 float y2;
14 float pie;
15 float pie2;
16 char stepschar[100];
17
18 int main()
19 {
20
21    printf("\n");
22    printf("\n");
23    printf("Berechne Pie...\n");
24    printf("\n");
25    printf("Genauigkeit - [steps] ? : ");
26
27    fgets(stepschar, sizeof(stepschar), stdin);
28    sscanf(stepschar, "%d", &steps);
29
30    counter2 = 0;
31    hits = 0;
32    pie2 = 1;
33
34       for (counter1 = 1; counter1 <= steps; ++counter1)
35        {
36          x = rand( ); 
37          y = rand( );
38
39          x2 = x / RAND_MAX; 
40          y2 = y / RAND_MAX;
41         
42          printf("%7d. Vektor: ( %f , %f )\n", counter1, x2, y2);
43  
44          if( ( x2 * x2 + y2 * y2) <= 1 )
45          ++hits;
46
47          // counter3 = counter1;
48
49          pie2 = pie2 * ((float)(( 2 * counter1 ) * ( 2 * counter1 )) / (float)((( 2 * counter1 ) * ( 2 * counter1 )) - 1 ));
50
51          counter2 = counter2 + x2 + y2;
52        }
53
54       pie = (4.0 * hits) / steps;
55       pie2 = 2 * pie2;
56
57    printf("\n");
58    printf("\tPie  :\t %1.8f\n", pie);
59    printf("\tProbe:\t %1.8f  (nah an 0.5 ?...)\n\n", counter2 / ( 2.0 * steps ));
60    printf("\tAus Rekursion:\t %1.8f\n", pie2);
61
62 return (0);
63 }