Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Factorial.h
- // Sort
- //
- // Created by me on 1/15/13.
- // Copyright (c) 2013 me. All rights reserved.
- //
- #ifndef Sort_Factorial_h
- #define Sort_Factorial_h
- #define FACTORIAL(__TYPE__, n) _factorial_##__TYPE__(n)
- #define CREATE_FACTORIAL_FUNC_WITH_TYPE(__TYPE__) \
- static inline __TYPE__ _factorial_##__TYPE__(__TYPE__ n) { \
- return ((((n) == 0))?1:((n) * FACTORIAL(__TYPE__, ((n) - 1)))); \
- }
- #endif
- //
- // main.c
- // Sort
- //
- // Created by me on 1/14/13.
- // Copyright (c) 2013 me. All rights reserved.
- //
- #include <stdio.h>
- #include "Factorial.h"
- CREATE_FACTORIAL_FUNC_WITH_TYPE(long);
- int main(int argc, const char * argv[]) {
- long result = FACTORIAL(long, 5);
- printf("%ld\n", result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement