0

# n = int(input()) length = 0 while n > 0: n //= 10 length += 1 print(length)

can anyone explain this..?

3 Answers

+ 3

It gets the digit of a number by division by 10.
The reason of floor division is to get rid of the decimal.
For example input 428
428 // 10 = 42 length = 1
42 // 10 = 4 length = 2
4 // 10 = 0 length = 3
0 > 0 is false, loop ends.

+ 3

Your code is simple first you taking number which type will be int and u take another variable length which will cout the length of Entered number . Your loop will run upto >0 times if condition will false then you will exit from loop
In next line you wrote n//=10 if you will divide number by 10 it will seperate your number and length += 1 will count total number.
if u will run of rough copy you can understood much better

2

which interpreter can run this as is and produce result or without an error?

Hot today

What is indentations... ?

6 Votes

Application RAM usage

1 Votes

Showing errors!

2 Votes

About Java McQ

0 Votes

Q. Anna is 18 years old

-2 Votes

int num = 2;
int x = 3;
if(num >= 2) {
if(x > 4) { num = 3; }
else { num = 4; }
}
else {x = 1; }

1 Votes

Balconies Problem in C

0 Votes