Last active
October 25, 2019 20:08
-
-
Save nbervar21/efa47ed97291204840282719f4e6e846 to your computer and use it in GitHub Desktop.
cs50 oneline credit
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
// credit.c by Nick Bervar (2019) | |
#include <stdio.h> | |
#include <cs50.h> | |
#include <math.h> | |
int main(void) | |
{ | |
long long c = 0, t = 0; | |
for (; c < 1; c = get_long_long("Number: ")); | |
for (int i = 1, q = c; l = log10(c); i < l; i++) | |
{ | |
q /= (10 + ((t += ((q % 10) * (((i % 2) == 0) ? 2 : 1)) - (((i % 2) == 0 && ((q % 10) * 2) > 9) ? 9 : 0)) * 0)); | |
} | |
printf(((t % 10) != 0) ? "INVALID\n" : (((log10(c) == 14) && (c / pow(10, log10(c) - 1) == 34 || c / pow(10, log10(c) - 1) == 37)) ? "AMEX\n" : (((log10(c) == 15) && (c / pow(10, log10(c)) == 5 && (c / (int) pow(10, log10(c) - 1)) % 10 > 0 && (c / (int) pow(10, log10(c) - 1)) % 10 < 6)) ? "MASTERCARD" : (((log10(c) == 12 || log10(c) == 15) && (c / pow(10, log10(c)) == 4)) ? "VISA\n" : "INVALID\n")))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment