CREDIT CARD CHECKING PROGRAM

This program is to check a credit card number weather it is valid or not .A valid credit card is a 16 digit number would satisfy the following rule.
  • from rightmost digit -1 every digit is multiplied by 2.
  • and digits which is multiplied by 2 should not be greater than 10.
  • and sum of all the digits will be equal to 38.
  • and sum of other digits which is not multiplied by 2 will be equal to 42.
  • and adding sum1 and sum2 will give 80 which is divisible by 10 
then this will be a valid credit card number.
The following dummy credit card number will show all the above given points:

4   5   6   7            1    2    3   4   5   6   7   8   9   1   2   9    

8       12               2           6        10     14      18       4


Then subtract 9 from the numbers greater than 10
8 3 2 6 1 5 9 4
Add them all up to get 38.
Add all other digits to get 42 ,the digits which is not multiplied by 2:
   5      7                2      4      6      8      1      9
sum of 32 and 42 is 80 is divisible by 10, the credit card is valid
here it is given in the program:


#include<stdio.h>
#include<conio.h>
void main()
{
int a[16]={4,5,6,7,1,2,3,4,5,6,7,8,9,1,2,9},i,sum=0,sum2=0;
int s;
clrscr();
for(i=14;i>=0;i=i-2)
{
a[i]=a[i]*2;
if(a[i]>=10)
{
a[i]=a[i]-9;
}
sum+=a[i];
}

for(i=15;i>0;i=i-2)
{
sum2+=a[i];
}
s=sum+sum2;
if(s==80&&s%10==0)
printf("The credit card is valid");
else
printf("The credit card is not valid");
          
       getch();

}

Comments

Popular posts from this blog

Pre-compiled Headers

CONNECTING WITH FTP-FILE TRANSFER PROTOCOL

PROBING THE INTERNET WITH TELNET: