this is my implementation of LUHN algorithm In my code for the input i want to create an array of values whose length can vary according to the user input. below is what i tried but seems to be not working ...also if i need to use malloc function how can i use is it ? other than that everything works fine ,also suggest some optimizations that can be made.
#include<stdio.h>
int main()
{ char a[100];
int sum=0,c=0,i;
printf("enter the card you use\n");
scanf("%16s",&a[i]);
for(int m=0;a[m]!='\0';m++){
c++;
}
for(int j=0;j<c;j++){
int k,l;
if(j%2==0){
k=a[j]%10;
l=a[j]/10;
a[j]=k+l;
sum=sum + a[j];
}
else{
sum = sum + 2*a[j];
}
}
if(sum % 10 ==0 && c==13)
printf("VISA\n");
else if(sum % 10==0 && c==16)
printf("MASTERCARD\n");
else if(sum % 10==0 && c==15)
printf("AMERICAN EXPRESSWAY\n");
else
printf("INVALID\n");
return 0;
}