Calculations: the remainder and Риёзӣ
In this lesson: you will find the remainder of a division, round numbers, and use the functions of Риёзӣ ("math").
Lesson 6
РиёзӣРиёзӣIn this lesson: you will find the remainder of a division, round numbers, and use the functions of Риёзӣ ("math").
РиёзӣIn this lesson: you will find the remainder of a division, round numbers, and use the functions of Риёзӣ ("math").
%а % б 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.
Риёзӣ.поёнРиёзӣ.поён(х) drops the decimal part (it rounds down):
1тағ дақиқаҳо = хонданиРақам();2тағ соат = Риёзӣ.поён(дақиқаҳо / 60);3тағ боқӣ = дақиқаҳо % 60;4чоп(соат, "соат", боқӣ, "дақиқа");
135
Риёзӣ| Function | Meaning | Example | Result |
|---|---|---|---|
Риёзӣ.поён(х) | 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чоп("Яклухт:", Риёзӣ.дузкунӣ(масоҳат));
5 / 0 does not give an error; the result is беохир ("infinity").Риёзӣ.Поён with a capital letter: names must be written exactly as they are.Read a number of minutes and turn it into hours and minutes: 2 соат 15 дақиқа.
Input: One number: the minutes.
Output: Н соат М дақиқа
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.
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 Боқӣ: …
Read the two legs of a right triangle and print the hypotenuse: the square root of а * а + б * б.
Input: Two lines: the legs.
Output: The hypotenuse.