automated commit by check50 [check50=True]

This commit is contained in:
kukemuna 2024-02-21 23:09:19 +02:00
parent 2e4ee96f07
commit bd1536199f
1 changed files with 21 additions and 16 deletions

View File

@ -6,6 +6,7 @@ long long get_card_number(void);
void find_issuer(long long card_number); void find_issuer(long long card_number);
int validate(long long card_number); int validate(long long card_number);
int get_id(long long card_number); int get_id(long long card_number);
int get_length(long long card_number);
int main(void) int main(void)
{ {
@ -32,24 +33,24 @@ long long get_card_number()
void find_issuer(long long card_number) void find_issuer(long long card_number)
{ {
int id = get_id(card_number); int id = get_id(card_number), count = get_length(card_number);
// Number beginning with 34 or 37 // Number beginning with 34 or 37 and length is 15
if (id / 100 == 34 || id / 100 == 37) if ((id / 100 == 34 || id / 100 == 37) && count == 15)
{ {
printf("AMEX\n"); printf("AMEX\n");
return; return;
} }
// Number beginning with 4 // Number beginning with 4 and length is 13 or 16
if (id / 1000 == 4) if ((id / 1000 == 4) && (count == 13 || count == 16))
{ {
printf("VISA\n"); printf("VISA\n");
return; return;
} }
// Number beginning with 51-55 or 2221-2720 // Number beginning with 51-55 or 2221-2720 and length is 16
if ((id / 100 >= 51 && id / 100 <= 55) || (id >= 2221 && id <= 2720)) if (((id / 100 >= 51 && id / 100 <= 55) || (id >= 2221 && id <= 2720)) && count == 16)
{ {
printf("MASTERCARD\n"); printf("MASTERCARD\n");
return; return;
@ -108,17 +109,9 @@ int validate(long long card_number)
int get_id(long long card_number) int get_id(long long card_number)
{ {
int count = 0, id; int count = get_length(card_number), id;
long long n, trunc = 1; long long n, trunc = 1;
n = card_number;
while (n > 0)
{
n /= 10;
count++;
}
if (count < 13 || count > 16) if (count < 13 || count > 16)
{ {
return 0; return 0;
@ -131,3 +124,15 @@ int get_id(long long card_number)
id = card_number / trunc; id = card_number / trunc;
return id; return id;
} }
int get_length(long long card_number)
{
int count = 0;
while (card_number > 0)
{
card_number /= 10;
count++;
}
return count;
}