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