Advertisement
paulogp

Macro

Jul 13th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. // title: macro
  2. // ide: apple xcode
  3. // author: paulogp
  4.  
  5. #include <stdio.h>
  6.  
  7. // macros
  8. #define MIN(a, b) ((a) > (b) ? (b) : (a))
  9.  
  10. #define MAX(a, b) ({\
  11.   typeof (a) _a = (a); \
  12.   typeof (b) _b = (b); \
  13.   _a > _b ? _a : _b; })
  14.  
  15. #define SQ(a) (a * a)
  16.  
  17. int main (int argc, const char * argv[])
  18. {
  19.     // using macro
  20.     int the_a, the_b;
  21.  
  22.     printf("a: ");
  23.     scanf("%i", &the_a);
  24.  
  25.     printf("b: ");
  26.     scanf("%i", &the_b);
  27.  
  28.     // outputs
  29.     printf("min = %i\n", MIN(the_a, the_b));
  30.     printf("max = %i\n", MAX(the_a, the_b));
  31.     printf("%i^2 = %i\n", the_a, SQ(the_a));
  32.  
  33.     puts(__FILE__); // macro pre-definida
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement