Skip to content

Instantly share code, notes, and snippets.

@cohalz
Created October 1, 2013 04:42
Show Gist options
  • Save cohalz/6773946 to your computer and use it in GitHub Desktop.
Save cohalz/6773946 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(){
int n;
int count = 0;
printf("n = ");
if(scanf("%d", &n) != 1) {
puts("Wrong input.");
return 1;
}
while(n != 1){
if(n%2 == 0){
n = n/2;
} else {
n = 3*n+1;
}
count++;
}
printf("%d\n",count);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment