Upstream version 1.3.40
[profile/ivi/swig.git] / Examples / python / multimap / example.c
1 /* File : example.c */
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <ctype.h>
5
6 /* Compute the greatest common divisor of positive integers */
7 int gcd(int x, int y) {
8   int g;
9   g = y;
10   while (x > 0) {
11     g = x;
12     x = y % x;
13     y = g;
14   }
15   return g;
16 }
17
18 int gcdmain(int argc, char *argv[]) {
19   int x,y;
20   if (argc != 3) {
21     printf("usage: gcd x y\n");
22     return -1;
23   }
24   x = atoi(argv[1]);
25   y = atoi(argv[2]);
26   printf("gcd(%d,%d) = %d\n", x,y,gcd(x,y));
27   return 0;
28 }
29
30 int count(char *bytes, int len, char c) {
31   int i;
32   int count = 0;
33   for (i = 0; i < len; i++) {
34     if (bytes[i] == c) count++;
35   }
36   return count;
37 }
38
39 void capitalize(char *str, int len) {
40   int i;
41   for (i = 0; i < len; i++) {
42     str[i] = (char)toupper(str[i]);
43   }
44 }
45
46 void circle(double x, double y) {
47   double a = x*x + y*y;
48   if (a > 1.0) {
49     printf("Bad points %g, %g\n", x,y);
50   } else {
51     printf("Good points %g, %g\n", x,y);
52   }
53 }