# How can I add alternate digits in credit.c?

I am currently trying to solve the hacker version of pset 1 (`credit.c`). I have successfully completed the rest of the psets (hacker and standard versions). I need to sum up the even (starting from 0) digits or alternate placing digits. E.g., given the number 5677, I need to have a program that will sum up 5 + 7 = 12, since they are even placing. The first digit is when `i == 0`.

My idea for this is to get an input from the user using:

``````Long n;
n = GetLongLong();
int sum;
``````

then using `sprintf` to convert my `Long n` into a string, `s`. After which, I can add the characters of the string (using `s[i]` for some `i < strlen(s)`) by using:

``````for (int i=0, i < strlen(s), i++)
{
for (i % 2 == 0)
sum = sum + s[i]
}
``````

But I don't know how to program this into the actual C language, especially the conversion from Long to Strings. Is my design of the program actually correct?

First, `char` is NOT `int`. I mean if you have

``````string s = "1234";
``````

and then you wrote something like

``````int sum = 0;

// iterate over s and sum the chars up
for (int i = 0, n = strlen(s); i < n; i++)
{
sum += s[i];
}
``````

`sum` won't be `10`!

Lastly, you may the remainder operator (i.e., `%`) to extract the digits of an `int` and either deal with them directly or store them in an `int` array and deal with them.
3. We want to add up only odd digits, so our update statement should decrement i in two every step: `for (int i = lastIndex; 0 <= i; i -= 2)`