C_dumping-ground/3xplus1.c

36 lines
1 KiB
C
Raw Normal View History

#include <stdio.h> //printf and shit
int main( int argc, char *argv[] ) { //yoinked from the internet argc is number of args and argv is a "array of arguments"
int x; //idk what types are i think this is a 32bit signed int... idk @quantum help... also should this even be here or should it be out of main
2022-01-23 05:56:35 -05:00
if (argc != 2) {
puts("fix your arguments");
return 0; //idk if this is how i should return an error idk @quantum rip my code to shreads
}
x = atoi(argv[1]); //mmmm yes the atoi is made out of atoi
2022-01-23 05:56:35 -05:00
if (x == 0) {
puts("uhhhh you entered 0 this wont end");
return 0;
2022-01-23 05:56:35 -05:00
} else {
printf("Got: %d\n", x);
}
2022-01-23 05:56:35 -05:00
while (x != 1) { //while x is not true i think
printf("%d\n",x ); //shit like this was difficualt in asm because i had to preserve all my registers
2022-01-23 05:56:35 -05:00
if (x & 1 == 1) { //if x is odd
x = (3 * x) + 1;
2022-01-23 05:56:35 -05:00
} else { //elses should be on the same line as the } from the above if
x = x / 2;
}
}
puts("number reaches one");
return 0;
}