Created
October 22, 2015 00:56
-
-
Save Isweet/9042f3ee6984ac2a9ef9 to your computer and use it in GitHub Desktop.
A powerful demonstration of the ternary operator!
This file contains 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
#!/bin/bash | |
cat << EOF > ./ternary.c | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
int main(int argc, char *argv[]) { | |
int a, b, c, d, e, f, g; | |
srand(time(NULL)); | |
a = rand() % 10 + 1; | |
b = rand() % 10 + 1; | |
c = rand() % 10 + 1; | |
d = rand() % 10 + 1; | |
e = (f = (a > b ? a : b)) > (g = (c > d ? c : d)) ? f : g; | |
printf("a = %d, b = %d, c = %d, d = %d, max = %d\n", a, b, c, d, e); | |
return 0; | |
} | |
EOF | |
gcc ./ternary.c -o ternary; for i in `seq 1 10`; do sleep 1 && ./ternary; done; rm -rf ./ternary ./ternary.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment