~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Examples/java/multimap/example.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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] = 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
}