moved test/* to beginners/ directory
authorhackbard <hackbard>
Thu, 6 Jun 2002 11:02:46 +0000 (11:02 +0000)
committerhackbard <hackbard>
Thu, 6 Jun 2002 11:02:46 +0000 (11:02 +0000)
asci.c [new file with mode: 0644]
ggt.c [new file with mode: 0644]
pie.c [new file with mode: 0644]
pie_improved.c [new file with mode: 0644]

diff --git a/asci.c b/asci.c
new file mode 100644 (file)
index 0000000..f679e51
--- /dev/null
+++ b/asci.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+main()
+{
+int i;
+for (i=0; i<=530; ++i)
+       {
+       printf("%d = %c\n",i, (char)(i));
+       }
+}
diff --git a/ggt.c b/ggt.c
new file mode 100644 (file)
index 0000000..b15e0f8
--- /dev/null
+++ b/ggt.c
@@ -0,0 +1,37 @@
+/* program to calculate the ggt of two integers */
+
+/* we include headers */
+#include <stdio.h>
+
+main()
+{
+
+/* declaration of variables */
+int zaehler, nenner;
+
+printf("Zaehler: ");
+scanf("%d",&zaehler);
+printf("Nenner: ");
+scanf("%d",&nenner);
+
+if ( nenner == 0 )
+       {
+       printf("never devide through zero, lamer :p\n");
+       exit(0);
+       }
+else
+       {
+       while ( zaehler != nenner )
+               {
+               if ( zaehler > nenner )
+                       {
+                       zaehler = zaehler - nenner;
+                       }
+               else
+                       {
+                       nenner = nenner - zaehler;
+                       }
+               }
+       printf("ggt = %d\n",zaehler);
+       }
+}
diff --git a/pie.c b/pie.c
new file mode 100644 (file)
index 0000000..1039689
--- /dev/null
+++ b/pie.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+int counter1;
+float counter2;
+int steps;
+int hits;
+float x;
+float x2;
+float y;
+float y2;
+float pie;
+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;
+
+      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;
+
+         counter2 = counter2 + x2 + y2;
+
+       }
+
+      pie = (4.0 * hits) / steps;
+
+   printf("\n");
+   printf("\tPie  :\t %1.8f\n", pie);
+   printf("\tProbe:\t %1.8f  (nah an 0.5 ?...)\n\n", counter2 / ( 2.0 * steps ));
+
+return (0);
+}
diff --git a/pie_improved.c b/pie_improved.c
new file mode 100644 (file)
index 0000000..860c816
--- /dev/null
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+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);
+}