fun f(x: Double): Double {
return x * x + 2 * x
}
fun rectanglesMethod(a: Int, b: Int, n: Int): Double {
val rectangleWidth = (b - a).toDouble() / n.toDouble()
var area = 0.0
var currentPoint = a.toDouble()
for (i in 1..n) {
currentPoint += rectangleWidth
val rectangleHeight = f(currentPoint)
area += rectangleHeight * rectangleWidth
}
return area
}
fun main() {
val a = 0
val b = 10
val n = 100
val area = rectanglesMethod(a, b, n)
println(area)
}
ZnVuIGYoeDogRG91YmxlKTogRG91YmxlIHsKICAgIHJldHVybiB4ICogeCArIDIgKiB4Cn0KCmZ1biByZWN0YW5nbGVzTWV0aG9kKGE6IEludCwgYjogSW50LCBuOiBJbnQpOiBEb3VibGUgewogICAgdmFsIHJlY3RhbmdsZVdpZHRoID0gKGIgLSBhKS50b0RvdWJsZSgpIC8gbi50b0RvdWJsZSgpCiAgICB2YXIgYXJlYSA9IDAuMAogICAgdmFyIGN1cnJlbnRQb2ludCA9IGEudG9Eb3VibGUoKQoKICAgIGZvciAoaSBpbiAxLi5uKSB7CiAgICAgICAgY3VycmVudFBvaW50ICs9IHJlY3RhbmdsZVdpZHRoCiAgICAgICAgdmFsIHJlY3RhbmdsZUhlaWdodCA9IGYoY3VycmVudFBvaW50KQogICAgICAgIGFyZWEgKz0gcmVjdGFuZ2xlSGVpZ2h0ICogcmVjdGFuZ2xlV2lkdGgKICAgIH0KCiAgICByZXR1cm4gYXJlYQp9CgoKZnVuIG1haW4oKSB7CiAgICB2YWwgYSA9IDAKICAgIHZhbCBiID0gMTAKICAgIHZhbCBuID0gMTAwCiAgICAKICAgIHZhbCBhcmVhID0gcmVjdGFuZ2xlc01ldGhvZChhLCBiLCBuKQogICAgCiAgICBwcmludGxuKGFyZWEpCn0=