Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // title: macro
- // ide: apple xcode
- // author: paulogp
- #include <stdio.h>
- // macros
- #define MIN(a, b) ((a) > (b) ? (b) : (a))
- #define MAX(a, b) ({\
- typeof (a) _a = (a); \
- typeof (b) _b = (b); \
- _a > _b ? _a : _b; })
- #define SQ(a) (a * a)
- int main (int argc, const char * argv[])
- {
- // using macro
- int the_a, the_b;
- printf("a: ");
- scanf("%i", &the_a);
- printf("b: ");
- scanf("%i", &the_b);
- // outputs
- printf("min = %i\n", MIN(the_a, the_b));
- printf("max = %i\n", MAX(the_a, the_b));
- printf("%i^2 = %i\n", the_a, SQ(the_a));
- puts(__FILE__); // macro pre-definida
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement