Take the Derivative

Сообщения
1,532
Реакции
271
Веб-сайт
tehadm.ru
Не знаю как членораздельно перевести на русский условие задачи, поэтому выкладываю оригинал.:cool:

This function takes two numbers as parameters, the first number being the coefficient, and the second number being the exponent.

Your function should multiply the two numbers, and then subtract 1 from the exponent. Then, it has to return an expression (like 28x^7). "^1" should not be truncated when exponent = 2.
For example:
derive(7, 8)
In this case, the function should multiply 7 and 8, and then subtract 1 from 8. It should output "56x^7", the first number 56 being the product of the two numbers, and the second number being the exponent minus 1.
C-like:
derive(7, 8) --> this should output "56x^7"
derive(5, 9) --> this should output "45x^8"

Notes:
  • The output of this function should be a string
  • The exponent will never be 1, and neither number will ever be 0
 
C-like:
package main

import (
    "fmt"
    "strconv"
)

func main() {
    var coefficient, exponent int
    fmt.Scan(&coefficient, &exponent)
    fmt.Println(Derive(coefficient, exponent))
}

func Derive(coefficient, exponent int) string {
    num1 := coefficient * exponent
    num2 := exponent - 1
    result := strconv.Itoa(num1) + "x^" + strconv.Itoa(num2)
    return result
}
 
C-like:
func Derive(coefficient, exponent int) string {
  return strconv.Itoa(coefficient * exponent) + "x^" + strconv.Itoa(exponent - 1)
}
 
Назад
Сверху Снизу