The problem can be solved in two ways:
Read the input data until the end of the file.
Algorithm implementation
Read the input data until the end of the file.
while(scanf("%lf",&x) == 1)
{For each test case compute and print the answer.
y = x * x * x + 2 * x * x - 3;
printf("%.4lf\n",y);
}Algorithm implementation — function
Define the f function.
double f(double x)
{
return x * x * x + 2 * x * x - 3;
}Read the input data until the end of the file. Compute and print the answer.
while(scanf("%lf",&x) == 1)
printf("%.4lf\n",f(x));Java implementation
import java.util.*;
public class Main
{
static double f(double x)
{
return x * x * x + 2 * x * x - 3;
}
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
while(con.hasNext())
{
double x = con.nextDouble();
System.out.println(f(x));
}
con.close();
}
} Python implementation — function
import sysDefine the f function.
def f(x):
return x ** 3 + 2 * x * x – 3Read the input data until the end of the file. Compute and print the answer.
for x in sys.stdin:
x = float(x)
print(f(x))Python implementation
import sysRead the input data until the end of the file.
for x in sys.stdin:For each test case compute and print the answer.
x = float(x)
y = x ** 3 + 2 * x * x – 3
print(y)