Assignment 5 Question 1

#include <stdio.h>
int collatz(int n, int count)
{
if(n==1){
return count;
}
if(n%2==0){
n=n/2;
count++;
}else if(n%2!=0){
n=3*n+1;
count++;
}
    return collatz(n,count);
}
int main()
{
int n,flag;
scanf("%d", &n);
flag=collatz(n,0);
printf("%d", flag);
return 0;
}

Comments

Popular posts from this blog

Assignment 6 Question 3

Assignment 8 Question 1

Assignment 7 Question 2