8831. Value of expression 1

 

Compute the value of the expression for the given real numbers x and y.

 

Input. Two real numbers x and y.

 

Output. Print the value of the given expression with precision to the thousandths.

 

Sample input

Sample output

1.000 -2.000

21.857

 

 

SOLUTION

mathematics

 

Algorithm analysis

To solve the problem, compute the value of the given expression.

 

Algorithm implementation

Read the input data.

 

scanf("%lf %lf", &x, &y);

 

Compute the value of the expression in the variable z.

 

z = 2 * x * x - 4 * x * y + 3 * y * y + (x + y) / 7;

 

Print the answer with precision to the thousandths.

 

printf("%.3lf\n", z);

 

Java implementation

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    double x = con.nextDouble();

    double y = con.nextDouble();

    double z = 2 * x * x - 4 * x * y +3 * y * y + (x + y) / 7;

    System.out.println(z);

    con.close();

  }

}

 

Python implementation

Read the input data.

 

x, y = map(float, input().split())

 

Compute the value of the expression in the variable z.

 

z = 2 * x * x - 4 * x * y + 3 * y * y + (x + y) / 7;

 

Print the answer.

 

print(z)