Skip to content

Instantly share code, notes, and snippets.

@noobermin
Last active February 5, 2016 06:21
Show Gist options
  • Save noobermin/1d6fb368f26341b1f3b7 to your computer and use it in GitHub Desktop.
Save noobermin/1d6fb368f26341b1f3b7 to your computer and use it in GitHub Desktop.
triangle numbers no ifs
#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