Arama butonu
Bu konudaki kullanıcılar: 1 misafir
2
Cevap
955
Tıklama
0
Öne Çıkarma
LUHN ALGORİTMASI
B
5 yıl
Yüzbaşı
Konu Sahibi

Luhn algoritması ve hangi kredi kartı olduğunu bulma hakkında c programlama ile bana yardımcı olursanız çok sevinirim. Hangi kredi kartı olduğunu bulma kısmı switch case ile olması gerekiyor.

DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.

Üye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.

Üye Ol Şimdi Değil



D
5 yıl
Yarbay

Sağ olasın donanım haberin Google Rankı. Ödev yazdılar ya, ışığı gören geliyor.



#include <stdio.h>
#include <cs50.h>
#include <math.h>

int main(void)
{
printf("Please give me your credit card number: ") ;

long long card_num = 0LL;

while (card_num < 1LL || card_num > 9999999999999999LL)
{
card_num = GetLongLong();
}

// Make a copy of the card number to be used and modified throughout the process.

long long temp_num = card_num;

// Isolate every digit from the credit card number using a loop and the variable 'digit'.
// Keep track of the amount and position of each digit using variable 'count'.

int count = 0;

while (temp_num > 0LL)
{
temp_num = temp_num / 10LL;
count++;
}

// If the number entered doesn't have the right amount of digits according
// to variable 'count', declare the number as invalid.

if (count != 13 && count != 15 && count != 16)
{
printf("This is an invalid number (# of digits).\n");
return 1;
}

// Reset value of variable 'temp_num' and apply calculations that will isolate the first two digits.
// Store the results in a variable 'company_id'.

temp_num = card_num;

while (temp_num > 100LL)
{
temp_num = temp_num / 10LL;
}

int company_id = temp_num;

// Print the type of credit card depending on the company ID and amount of digits.

if (company_id > 50 && company_id < 56 && count == 16)
{
printf("MASTERCARD\n") ;
}
else if ((company_id == 34 || company_id == 37) && (count == 15))
{
printf("AMEX\n") ;
}
else if ((company_id / 10 == 4) && (count == 13 || count == 16 || count == 19))
{
printf("VISA\n") ;
}
else
{
printf("This card was issued by an unknown company.\n");
}

// Apply Luhn's algorithm.

int sum = 0;

temp_num = card_num;

for (int i = 1; i <= count; i++)
{
int digit = temp_num % 10LL;

if (i % 2 == 0)
{
digit *= 2;

if (digit > 9)
{
digit -= 9;
}
}

sum += digit;

temp_num /= 10LL;
}

// Checking the validity of the number according to Luhn's algorithm

if (sum % 10 != 0)
{
printf("This is an invalid number (Luhn's algorithm).\n");
return 1;
}

printf("This is a valid number.\n");

return 0;
}


Size verilen eğitimin ben. Bari ingilizce ile arayın ya kıyamet gibi var.



Y
5 yıl
Çavuş

En sağdaki digit Check digit değeridir. Check digit değerinden başlayarak 1.,3.,5….. değerleri 2 ile çarparız. (2.,4.,6. … değerler aynı kalır.)
Eğer değerlerin toplamı 9’dan büyükse rakamlarını toplayıp rakamların toplamını buluruz.
Nihai olarak elde edilen tüm rakamlar toplanır.
Rakamların toplamı 9 ile çarpılır.
Elde edilen rakamın son hanesi check digit değeridir.



< Bu ileti mini sürüm kullanılarak atıldı >

DH Mobil uygulaması ile devam edin. Mobil tarayıcınız ile mümkün olanların yanı sıra, birçok yeni ve faydalı özelliğe erişin. Gizle ve güncelleme çıkana kadar tekrar gösterme.