Advertisement
bigyan

Syntactic Sugar in C

Apr 15th, 2011
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define until(x)    while(!(x))
  5. #define unless(x)   if(!(x))
  6.  
  7. unsigned int factorial(unsigned int n) {
  8.     unsigned int fact=1, i;
  9.     until ( n==0 )
  10.         fact *= n--;
  11.     return fact;   
  12. }
  13.  
  14. int main(int argc, char*argv[]) {
  15.     unless (argc==2)
  16.         puts("Usage: fact <num>");
  17.     else {
  18.         int n = atoi(argv[1]);
  19.         if (n<0)
  20.             puts("please give +ve number");
  21.         else
  22.             printf("factorial(%u) = %u\n",n,factorial(n));
  23.     }
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement