+ 1
Why does this not work?
I know, this is a bad question, but I have no idea what I have done wrong. I tried to make a C code to that Collatz Conjecture-thing, but it doesn't work and I have no idea why. Here's the code: https://code.sololearn.com/cfDKYhrjhb9X/?ref=app It's btw my first C code, if we don't count some testing with input / output...
4 Answers
+ 5
Hey, that's not how scanf works.
What you're doing is, you're applying atoi on what is returned by scanf.
Scanf returns the number of inputs read and assigned successfully. And in this case, you're not giving reference to any variable inside the scanf in which the input value would be stored and hence scanf will return 0. And thus, your i will have a value 0 and hence won't go inside while loop.
You should do it like:
int i;
scanf("%d", &i);
+ 3
Coincidentally, your in-/output was the issue. The logic was correct. Here is how it should look:
https://code.sololearn.com/cpif2RfhHkL4/?ref=app
You might want to look at printf and scanf again, then you'll see the mistakes by yourself.
+ 2
Thank you, Shadow and Shashi Ranjan
As I said, this was practically my first C code, so thanks for the help.
+ 1
I made it work, thank you.
https://code.sololearn.com/c2fU61PLVMla/?ref=app