PageRenderTime 36ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/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. /* Compute the greatest common divisor of positive integers */
  6. int gcd(int x, int y) {
  7. int g;
  8. g = y;
  9. while (x > 0) {
  10. g = x;
  11. x = y % x;
  12. y = g;
  13. }
  14. return g;
  15. }
  16. int gcdmain(int argc, char *argv[]) {
  17. int x,y;
  18. if (argc != 3) {
  19. printf("usage: gcd x y\n");
  20. return -1;
  21. }
  22. x = atoi(argv[1]);
  23. y = atoi(argv[2]);
  24. printf("gcd(%d,%d) = %d\n", x,y,gcd(x,y));
  25. return 0;
  26. }
  27. int count(char *bytes, int len, char c) {
  28. int i;
  29. int count = 0;
  30. for (i = 0; i < len; i++) {
  31. if (bytes[i] == c) count++;
  32. }
  33. return count;
  34. }
  35. void capitalize(char *str, int len) {
  36. int i;
  37. for (i = 0; i < len; i++) {
  38. str[i] = (char)toupper(str[i]);
  39. }
  40. }
  41. void circle(double x, double y) {
  42. double a = x*x + y*y;
  43. if (a > 1.0) {
  44. printf("Bad points %g, %g\n", x,y);
  45. } else {
  46. printf("Good points %g, %g\n", x,y);
  47. }
  48. }