0
Can somebody explain this code in depth?
So I copied this code online. https://code.sololearn.com/cRi02XQcFArk/#cpp I want to understand it. But i'm extremely confused. I just started learning c++ about 3 or 4 days ago. Somebody said c++ was pretty much JavaScript(How?. They seem entirely different.) I left some comments in the code that ask some questions. One of the main ones are why do we keep dividing by 10? Why did we need the remainder of the number divided by 10? lol amverysconfused
5 Antworten
+ 2
I answered each question you had directly in the code, I hope this helps in addition to what Ulisses Cruz has already pointed out before:
https://code.sololearn.com/cGF0Ggk1q0cP/?ref=app
Oh, and maybe that somebody meant Java, not Javascript. That would make more sense.
+ 2
Daniel Cooper if you want to count the number of digits of an integer n,
you can do that by dividing n by 10 and incrementing a counter,
until n == 0.
For example:
Imagine n = 1234 and counter = 0:
n = n / 10; counter++; // now n = 123 and counter = 1
n = n / 10; counter++; // now n = 12 and counter = 2
n = n / 10; counter++; // n = 1 and counter = 3
n = n / 10; counter++ ; // n = 0 and counter = 4
another point:
while(x) // loop while x != 0
+ 2
Another point:
if n = 1234,
r = n % 10 // r = 4 that's a way to get the rightmost digit of n
+ 2
Satnam Singh Nope. I showed this code to him, and at one point he mentioned it again.
Lol
Thanks my dude. This really helps
+ 2
And thanks to you too Ulisses Cruz