So in a week 3 short, Doug asks us to define a file collatz.c that returns the number of steps taken to do the collatz conjecture on different numbers and I ended up with this.
#include <stdio.h>
#include <cs50.h>
int collatz(int number, int y);
int main(void)
{
int number = get_int("Number: ");
int steps = collatz(number, 0);
printf("%i", steps);
}
int collatz(int number, int y)
{
if (number == 0)
{
return y;
}
else if (number % 2 == 0)
{
++y;
collatz(number / 2, y);
}
else
{
++y
collatz((3 * number) + 1, y);
}
return 0;
}
It compiles fine but after running gives "Segmentation fault (core dumped)". I don't really get why this is happening, can someone please help me with this one?