/tags/rel-1-3-25/SWIG/Examples/mzscheme/multimap/example.c
C | 53 lines | 46 code | 5 blank | 2 comment | 9 complexity | 59eadaf2f9ab96233bcc88e986e6c269 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
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 */ 7int 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 18int 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 30int 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 39void 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 46void 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}