O
O
OuTsider_012018-10-15 20:20:54
C++ / C#
OuTsider_01, 2018-10-15 20:20:54

Can you explain to a beginner?

int number, hundrets;
number = int.Parse(Console.ReadLine());
hundrets = number / 100%10 ;
A simple code that counts the number of hundreds, but how? I do not understand the work% 10. It is desirable to explain the algorithm in detail.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
#
#, 2018-10-15
@OuTsider_01

The % operator (C# Reference)
let's say you have the number 3333. Integer * division by 100 will result in 33. Strictly speaking, there are 33 hundreds. but if we are talking about the selection of exactly one digit of hundreds 3 3 33, that is, we need to get 3?
obviously that's what % does - it gives the remainder when divided by 10 . according to the laws of sharpe ps another example 1 2 34 / 100 = 1 2 1 2 % 10 = 2 * - with integer division, in strong typing languages, the fractional part is discarded 33 % 10 = 3

V
Vladislav Lyskov, 2018-10-15
@Vlatqa

% 10 - remainder after dividing by 10
999 / 100 == 9.99
999 / 100%10 == 9;

M
Maxim Isaev, 2018-10-15
@MaximIs

Divide 33 by 10. All that remains is the remainder of the division by 10.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question