Created
June 2, 2012 21:28
-
-
Save aji/2860007 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| char *prepend_lol(const char *nope) | |
| { | |
| char *yep = malloc(strlen(nope) + 5); | |
| sprintf(yep, "lol, %s", nope); | |
| return yep; | |
| } | |
| char *is_even(int n) | |
| { | |
| if (n < 0) | |
| return is_even(n + 2); | |
| if (n > 1) | |
| return is_even(n - 2); | |
| if (n == 0) | |
| return prepend_lol("yes, that's even"); | |
| else | |
| return prepend_lol("no, that's not even"); | |
| } | |
| int usage(char *argv0) | |
| { | |
| printf("use it like this: %s <some number>\n", argv0); | |
| return 1; | |
| } | |
| int main(int argc, char *argv[]) | |
| { | |
| int n; | |
| if (argc < 2) | |
| return usage(argv[0]); | |
| n = atoi(argv[1]); | |
| printf("you want to know if %d is even?\n", n); | |
| puts(is_even(n)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment