Function - 3#8241

Function - 3 (Editorial)

Implement the funtion f(x, y). Read the input data until the end of the file.

Algorithm realization

Implement the function f.

double f(double x, double y)
{
  return x * x + sin(x * y) - y * y;
}

The main part of the program. Read the input data until the end of the file.

while (scanf("%lf %lf", &x, &y) == 2)
  printf("%.4lf\n", f(x, y));

Java implementation

import java.util.*;

public class Main
{
  static double f(double x, double y)
  {
    return x * x + Math.sin(x * y) - y * y;
  }
	
  public static void main(String[] args)
  {
    Scanner con = new Scanner(System.in);
    while(con.hasNext())
    {
      double x = con.nextDouble();
      double y = con.nextDouble();
      System.out.printf("%.4f\n",f(x,y));
    }
    con.close();
  }
}   

Python implementation

import sys
import math

Implement the function f.

def f(x,y):
  return x * x + math.sin(x * y) - y * y

The main part of the program. Read the input data until the end of the file.

for x in sys.stdin:
  x, y =  map(float, x.split())
  print(f(x,y))