Вы можете избежать использования pow, имея счетчик, который вы умножаете на 10 при каждой итерации цикла.
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void) {
long long c = 1234123412341234;
long long temp_c = c;
long long temp_c_one = c;
long long c_one_x = 0;
long long pwr = 1; // 10^0 = 1
int count = 0;
while (temp_c > 0LL) {
temp_c = temp_c / 10LL;
count++;
}
// TODO: Don't think you should decrement count in this loop
for (int i = 0; i < count; i++) {
c_one_x = (temp_c_one % (pwr * 10)) / pwr;
count--;
pwr *= 10;
}
}
Однако , я не уверен, что вы создали хорошую реализацию алгоритма Лунса, поэтому я предлагаю следующее:
// Better Luhn's algorithm
int luhn( long long cc) {
unsigned long check = 0;
unsigned int digit;
for (int i = 0; cc > 0; i++) {
digit = cc % 10;
// double every second digit
if (i % 2) {
digit *= 2;
digit = (digit >= 10) ? (digit + 1) % 10 : digit;
}
check += digit;
cc = cc/10; // next CC digit.
}
return check;
}
int main (void) {
long long c = 1234123412341234;
print "Result is : %d", luhn(c));
}