A function with бозгашт
In this lesson: a function calculates a result and returns it.
Lesson 14
бозгаштбозгаштIn this lesson: a function calculates a result and returns it.
бозгаштIn this lesson: a function calculates a result and returns it.
бозгаштбозгашт means "return":
1функсия квадрат(х: рақам): рақам {2бозгашт х * х;3}45чоп(квадрат(4));6тағ натиҷа = квадрат(3) + квадрат(4);7чоп(натиҷа);
бозгашт х * х; returns the value to the place where the function was called.: рақам after the brackets says that the function returns a number.бозгашт, the function ends.1функсия калонтарин(а: рақам, б: рақам): рақам {2агар (а > б) {3бозгашт а;4}5бозгашт б;6}78чоп(калонтарин(3, 7));9чоп(калонтарин(калонтарин(1, 9), 4));
дуруст or нодуруст1функсия ҷуфтАст(н: рақам): мантиқӣ {2бозгашт н % 2 === 0;3}45тағ рақам = хонданиРақам();6агар (ҷуфтАст(рақам)) {7чоп("Ҷуфт");8} вагарна {9чоп("Тоқ");10}
12
чоп and бозгаштчоп shows a value on the screen; бозгашт gives it back to the program so that you can use it: in a calculation, in a variable or in a condition.
Write a function фаренгейт(с) ("fahrenheit") that converts a temperature from degrees Celsius to degrees Fahrenheit and returns it: с * 9 / 5 + 32. Read a temperature and print the result.
Input: One number: degrees Celsius.
Output: Degrees Fahrenheit.
Write a function соддаАст(н) ("isPrime(n)") that returns дуруст ("true") if н is a prime number (greater than 1 and divisible only by 1 and by itself). Read a number and print Содда ("Prime") or Содда нест ("Not prime").
Input: One whole number.
Output: Содда or Содда нест
Write a function дараҷа(асос, нишондиҳанда) ("power(base, exponent)") with a loop (without Риёзӣ.қувват and **). Read two numbers and print the result.
Input: Two numbers: the base, then the exponent (0 or more).
Output: The power.
Write a function калонтарин(а, б) ("greatest(a, b)") that returns the greater of two numbers. Read three numbers and print the greatest of them with the help of this function.
Input: Three numbers.
Output: The greatest.