Step1: Read in credit card number as a series of digits into an array the number
ID: 3871491 • Letter: S
Question
Step1: Read in credit card number as a series of digits into an array the number -1 is used to indicate the end of series, no need to read in -1 into the array The maximum size of the array is set to 20 Step2: Find sum1 (main should call a function passing array and size) lgnoring the last (right most digit) check digit of the credit card number, and moving left double the value of every second digit and find the sum of these doubled numbers. If the result of the doubling operation is a two digit number, you should add the digits of the doubled number before finding the sum. Step 3: find sum2 (main should call a function passing array and size) Find the sum of all other numbers (last digit is not included in this sum as well). Step 4: Calculate check sum Compute the total of sum1 and sum2 and multiply the result by 9, checksum is found by extracting the rightmost digitExplanation / Answer
#include <stdio.h>
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",&cardnum);
if(isvalid(cardnum)==1)
printf("Valid card number ");
else
printf("Invalid card number ");
return 0;
}
int isvalid(long num){
if(((sumofoddplace(num)+sumofdoubleevenplace(num))%10==0)
&& (getsize(num)<=16 && getsize(num)>=13)
&& (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<numdigits;i+=2){
sum+=getdigit((int)(2*(num % 10)));
num/=100;
}
return sum;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.