title: C: Credit Card Number checker/ Luhn's algorithm
body: <p>Everything looks fine and seems to follow Luhn's algorithm, but when i enter my own credit card number or this sample number that should be valid: 4388576018410707 , it still comes back as invalid...</p>
  
  <p>Can anyone find the problem?   </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int isvalid(long num);
  int sumofdoubleevenplace(long num);
  int getdigit(int num);
  int sumofoddplace(long num);
  int prefixmatched(long num,int d);
  int getsize(long d);
  int getprefix(long num,int k);
  
  main(){
    long cardnum=0;
    printf("Enter credit card number ");
    scanf("%ld",&amp;cardnum);
    if(isvalid(cardnum)==1)
      printf("Valid card number\n");
  else
      printf("Invalid card number\n ");
  return 0;
  }
  
  int isvalid(long num){
  if(((sumofoddplace(num)+sumofdoubleevenplace(num))%10==0)
     &amp;&amp; (getsize(num)&lt;=16 &amp;&amp; getsize(num)&gt;=13)
     &amp;&amp; (prefixmatched(num,4)==1 || prefixmatched(num,5)==1 ||
         prefixmatched(num,6)==1 || prefixmatched(num,37==1)))
      return 1;
  else
      return 0;
  }
  
  int sumofdoubleevenplace(long num){
  int numdigits=getsize(num)-1;
  int sum=0,i;
  num/=10;
  for(i=0;i&lt;numdigits;i+=2){
      sum+=getdigit((int)(2*(num % 10)));
      num/=100;
  }
  return sum;
  }
  
  int getdigit(int num){
  return ((num-num%10)/10)+num%10;
  }
  
  int sumofoddplace(long num){
  int numberofdigits=getsize(num);
  int sum=0,i;
  for(i=0;i&lt;numberofdigits;i+=2){
      sum+=num%10;
      num/=100;
  }
  return sum;
  }
  
  int prefixmatched(long num,int d){
  if(getprefix(num,getsize(d))==d)
      return 1;
  else
      return 0;
  }
  
  int getsize(long d){
  int n=0;
  while(d!=0){
      d/=10;
      n++;
  }
  return n;
  }
  
  int getprefix(long num,int k){
  int numberofdigits=getsize(num);
  int i;
  if(numberofdigits-k&gt;0){
      for(i=0;i&lt;numberofdigits-k;i++){
          num/=10;
      }
      return num;
  }
  else
      return num;
  }
  </code></pre>