PROGRAM TO CHECK WHETHER A CREDIT CARD NO. IS VALID OR NOT

Hi frnds, here to a c++ program for u which checks whether a credit card no. is valid or invalid.

Input:- 16 digit credit card no.

Output:- Valid or Invalid

Source code:-

#include"iostream.h"
#include"conio.h"
#include"graphics.h"

int credit_card_validity(int card_no[16])
    {
    int temp[8],i=0,j,sum=0;

    for(j=0;j<16 br="br" j="j+2)">        {
        temp[i++]=2*card_no[j];
        }

    for(i=0;i<8 br="br" i="i">        {
        sum=temp[i]/10+temp[i]%10+sum;
        }

    for(i=1;i<16 br="br" i="i+2)">        {
        sum=sum+card_no[i];
        }

        sum=sum%10;
        return(sum);

    }




int main()
{
clrscr();
int card_no[16],i;

cout<<"\nEnter credit card no.:";
for(i=0;i<16 br="br" i="i">cin>>card_no[i];


if(!credit_card_validity(card_no))
cout<<"\nCREDIT CARD IS VALID";
else
cout<<"\nINVALID CREDIT CARD";


getch();
return 0;
}

Popular Posts