In this post, we will solve **Area Under Curves and Volume of Revolving a Curve HackerRank Solution**. This problem** (Area Under Curves and Volume of Revolving a Curve)** is a part of **HackerRank Functional Programming** language.

**Task**

**Definite Integrals via Numerical Methods**

This relates to definite integration via numerical methods.

Consider the algebraic expression given by:

**(a1) x^{b1} + (a2)x^{b2} + (a3)x^{b3} + . . . . . + (an)x^{bn}**

For the purpose of numerical computation, the area under the curve ** y = f(x)** between the limits

*and*

**a***can be computed by the Limit Definition of a Definite Integral.*

**b**Here is some background about **areas and volume computation**.

Using equal subintervals of length **= 0.001**, you need to:

- Evaluate the area bounded by a given polynomial function of the kind described above, between the given limits of
and**L**.**R** - Evaluate the volume of the solid obtained by revolving this polynomial curve around the
-axis.**x**

A relative error margin of **0.01** will be tolerated.

**Input Format**

The first line contains * N* integers separated by spaces, which are the values of

**a1, a2, . . . , a**.

*N*The second line contains

*integers separated by spaces, which are the values of*

**N****b1, b2, . . . , b**.

*N*The third line contains two space separated integers,

*and*

**L***, the lower and upper range limits in which the integration needs to be performed, respectively.*

**R****Constraints**

**-1000 <=***a*<= 1000**-20 <=***b*<= 20**1 <=***L*<=*R*<= 20

**Output Format**

The first line should contain the area between the curve and the * x*-axis, bound between the specified limits.

The second line should contain the volume of the solid obtained by rotating the curve around the

*-axis, between the specified limits.*

**x****Sample Input**

```
1 2 3 4 5
6 7 8 9 10
1 4
```

**Explanation**

The algebraic expression represented by:

**(1) x^{6} + (2)x^{7} + (3)x^{8} + (4)x^{9} + (5)x^{10}**

We need to find the area of the curve enclosed under this curve, between the limits** x = 1** and

**4**. We also need to find the volume of the solid formed by revolving this curve around the

*-axis between the limits*

**x****and**

*x*= 1**4**.

**Sample Output**

```
2435300.3
26172951168940.8
```

**Scoring**

All test cases are weighted equally. You need to clear all the tests in a test case.

**Solution – Area Under Curves and Volume of Revolving a Curve – HackerRank Solution**

**Scala**

val step = 0.001 def area(coefficients: List[Int], powers: List[Int], x: Double): Double = { val r = f(coefficients, powers, x) r * r * math.Pi } // This function will be used while invoking "Summation" to compute // The area under the curve. def f(coefficients: List[Int], powers: List[Int], x: Double): Double = { coefficients.zip(powers).map { case (c, p) => c * math.pow(x, p) }.sum } def summation(func: (List[Int], List[Int], Double) => Double, upperLimit: Int, lowerLimit: Int, coefficients: List[Int], powers: List[Int]): Double = { (BigDecimal(lowerLimit) to upperLimit by step).map(x => func(coefficients, powers, x.toDouble)).sum * step } // readLine() is deprecated in Scala 13, but it is called by HackerRank's predefined code. // So it is added to fix the issue. def readLine(): String = scala.io.StdIn.readLine()

**Note:** This problem **(Area Under Curves and Volume of Revolving a Curves)** is generated by **HackerRank** but the solution is provided by **CodingBroz**. This tutorial is only for **Educational** and **Learning** purpose.