exercism/c/collatz-conjecture/collatz_conjecture.c

23 lines
276 B
C

#include "collatz_conjecture.h"
int steps(int start) {
if (start < 1) {
return ERROR_VALUE;
}
int count = 0;
while (start != 1) {
if (start % 2 == 0) {
start /= 2;
} else {
start = start * 3 + 1;
}
count++;
}
return count;
}