here is the code and error is"control may reach end of non-void function [-Werror,-Wreturn-type]"
#include #include int collatz( int n, int c); int main (void) { printf("please enter a positive int\n"); int n=GetInt(); int count=0; collatz (n,count); } int collatz (int n,int c) { while (n>0) { //base case is when n==1 if (n==1) { c++; //print number of repition to make it 1 printf("%i\n", c); return 0; } // if even else if ((n%2)==0) { return 1 + collatz(n/2,c++); } //if odd else return 1 + collatz(3*n+1,c++); } }>#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
int collatz( int n, int c);
int main (void)
{
printf("please enter a positive int\n");
int n=GetInt();
int count=0;
collatz (n,count);
}
int collatz (int n,int c)
{
while (n>0)
{
//base case is when n==1
if (n==1)
{
c++;
//print number of repition to make it 1
printf("%i\n", c);
return 0;
}
// if even
else if ((n%2)==0)
{
return 1 + collatz(n/2,c++);
}
//if odd
else
return 1 + collatz(3*n+1,c++);
}
}