Last active
February 5, 2016 06:21
-
-
Save noobermin/1d6fb368f26341b1f3b7 to your computer and use it in GitHub Desktop.
triangle numbers no ifs
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> | |
/* to compile | |
* cc noif.c -o noif | |
* | |
* Usage: ./noif | |
* ./noif <N> | |
* where <N> is an integer.*/ | |
fn(int n){ ((n>0) && (n = fn(n-1)+n)) || (n = 0); return n; } | |
main(int argc, char *argv[]){ | |
int n; | |
((argc > 1) && sscanf(argv[1], "%d", &n)) || /*for reading from command line*/ | |
(printf("number: "), scanf("%d",&n)); | |
printf("%d\n",fn(n)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment