Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Step1: Read in credit card number as a series of digits into an array the number

ID: 3890056 • 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 digit

Explanation / Answer

/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
int findsum1(int [],int);
int findsum2(int [],int);
int main()
{
int i,a[20],n,sum1,sum2,checksum,checksumDigit;
printf("Enter total no of digits in your credit card no.");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter your credit card no");
scanf("%d",&a[i]);
}
sum1 = findsum1(a,n);
sum2 = findsum2(a,n);
checksum=(sum1+sum2) * 9;
checksumDigit=checksum%10;
printf("The sum1=%d,sum2=%d,checksumDigit=%d",sum1,sum2,checksumDigit);
return 0;
}

int findsum1(int a[],int n)
{
int i,x,sum=0,fsum=0,tsum=0;
x=n-2;
do
{

sum=a[x]+a[x];
if (sum>9)
{
fsum=(sum/10)+(sum%10);
}
else
{
fsum=sum;
}
tsum=tsum+fsum;
x=x-2;
}while(x>=0);
  
return tsum;

}

int findsum2( int a[],int n)
{
int i,x,tsum2=0;
x=n-3;
do
{

tsum2+=a[x];

x=x-2;
  
}while(x>=0);
  
return tsum2;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote