I am trying not to use Arrays to solve this problem. However, the answer keeps showing as 0. Can someone pls help to explain?
Thanks a lot in advance!
Below is the code: I am trying 1. get the length of the credit card number 2. sum from the last digit up, i, i+2, i+4, until i < length of credit card number 3. sum from the second last digit up... But i am already stuck at step 2
int count=0;
while (number>0)
{
number=number/10;
count++;
}
int sum1=0;
int sum2=0;
int i;
for (i=0;i<count;i+=2)
{
sum1+=number % 10;
number= number/10;
}
printf("%i\n", sum1);