Lesson 6

Calculations: the remainder and Риёзӣ

Calculations: the remainder and Риёзӣ

In this lesson: you will find the remainder of a division, round numbers, and use the functions of Риёзӣ ("math").

The whole lesson on one page

Calculations: the remainder and Риёзӣ

In this lesson: you will find the remainder of a division, round numbers, and use the functions of Риёзӣ ("math").

The remainder: %

а % б is the remainder when you divide а by б:

1чоп(17 % 5);
2чоп(10 % 2);
3чоп(7 % 2);

You will need the remainder often: a number (рақам) is even if рақам % 2 is 0; the last digit of 123 is 123 % 10, that is, 3.

Division without the remainder: Риёзӣ.поён

Риёзӣ.поён(х) drops the decimal part (it rounds down):

1тағ дақиқаҳо = хонданиРақам();
2тағ соат = Риёзӣ.поён(дақиқаҳо / 60);
3тағ боқӣ = дақиқаҳо % 60;
4чоп(соат, "соат", боқӣ, "дақиқа");
Input
135

Other functions of Риёзӣ

FunctionMeaningExampleResult
Риёзӣ.поён(х)round downРиёзӣ.поён(3.7)3
Риёзӣ.боло(х)round upРиёзӣ.боло(3.2)4
Риёзӣ.дузкунӣ(х)round to the nearestРиёзӣ.дузкунӣ(3.5)4
Риёзӣ.мутлақ(х)absolute valueРиёзӣ.мутлақ(-5)5
Риёзӣ.дуръшака(х)square rootРиёзӣ.дуръшака(16)4
Риёзӣ.қувват(х, н)powerРиёзӣ.қувват(2, 10)1024
Риёзӣ.ПИthe number πРиёзӣ.ПИ3.14…
1тағ радиус = 3;
2тағ масоҳат = Риёзӣ.ПИ * радиус * радиус;
3чоп("Масоҳати доира:", масоҳат);
4чоп("Яклухт:", Риёзӣ.дузкунӣ(масоҳат));

Common mistakes

  • Dividing by zero: 5 / 0 does not give an error; the result is беохир ("infinity").
  • Риёзӣ.Поён with a capital letter: names must be written exactly as they are.

Task: Hours and minutes

Read a number of minutes and turn it into hours and minutes: 2 соат 15 дақиқа.

Input: One number: the minutes.

Output: Н соат М дақиқа

Task: Sum of digits

Read a three-digit number and print the sum of its digits. For example, for 123 the answer is 6. Hint: % 10 gives the last digit.

Input: A three-digit number.

Output: The sum of the digits.

Task: Sharing apples

Read the number of apples and the number of children. The apples are shared equally. Print how many apples each child gets and how many are left over.

Input: Two lines: the apples, then the children.

Output: Ҳар кас: … and Боқӣ: …

Task: Hypotenuse

Read the two legs of a right triangle and print the hypotenuse: the square root of а * а + б * б.

Input: Two lines: the legs.

Output: The hypotenuse.