From 536f57988cde7fb22e52b3c75b3986cd0a457e00 Mon Sep 17 00:00:00 2001 From: "Mr. Sam" Date: Sun, 19 Jul 2026 23:40:53 +0100 Subject: Remade because I kinda deleted the old, perfect version --- main.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 main.c (limited to 'main.c') diff --git a/main.c b/main.c new file mode 100644 index 0000000..7e289a3 --- /dev/null +++ b/main.c @@ -0,0 +1,29 @@ +#include +#include + +void PrintHelp(void) { + printf("Usage: collatz " + "\nMade by samuel@yakubos.org\n\n"); +} + +int main(int argc, char *argv[]) { + if ( argc < 2 || argc > 2) { + PrintHelp(); + return 1; + } + char *endptr; + long int num; + int steps = 0; + num = strtol(argv[1], &endptr, 10); + + printf("%li\n", num); + while ( num > 1 ) { + num = ( num & 1 ) ? num * 3 + 1 : num / 2; + printf("%li\n", num); + steps++; + } + + printf("%s took %d steps\n", argv[1], steps); + +} + -- cgit v1.2.3