Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (32 sloc) 597 Bytes
#include <stdio.h>
#include <stdlib.h>
int luhn_algorithm(char* kredi_kart_no){
if(strlen(kredi_kart_no) == 16){
int tek = 0, cift = 0;
int i;
for(i = 0; i < 16; i++){
if(i % 2 == 0){ // cift
cift += kredi_kart_no[i] - '0';
}else{ //tek
tek += kredi_kart_no[i] - '0';
}
}
int r = (cift + tek) % 10;
if(r != 0){
return 1;
}else{
return 0;
}
printf("Indis 0:%c",kredi_kart_no[0]);
}else{
return 0;
}
}
int main(int argc, char* argv[]) {
if(luhn_algorithm("4967881123109908")){
printf("Doğru!");
}else{
printf("Yanlış!");
}
return 0;
}