daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Aug 12th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. unsigned long reverse(unsigned long n) {
  6.     unsigned long r = 0;
  7.     while (n > 0) {
  8.         r += n % 10;
  9.         r *= 10;
  10.         n /= 10;
  11.     }
  12.     r /= 10;
  13.     return r;
  14. }
  15.  
  16. int main(int argc, char **argv) {
  17.     if (argc != 2) {
  18.         printf("Usage: %s number\n", argv[0]);
  19.         return 1;
  20.     }
  21.  
  22.     unsigned long n = strtoul(argv[1], NULL, 0);
  23.     unsigned long r = reverse(n);
  24.     printf("%lu reversed is %lu.\n", n, r);
  25.  
  26.     return 0;
  27. }
RAW Paste Data
Top