Simple function#8592

Simple function (Editorial)

Implement the function .

Algorithm implementation

Define the function f.

double f(double x)
{
  return x + sin(x);
}

The main part of the program. Read the input value .

scanf("%lf",&x);

Compute and print the value of the function .

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

Java implementation

import java.util.*;

public class Main
{
  static double f(double x)
  {
    return x + Math.sin(x);
  }

  public static void main(String[] args)
  {
    Scanner con = new Scanner(System.in);
    double x = con.nextDouble();
    double y = f(x);
    System.out.println(y);    
    con.close();
  }
}   

Python implementation

import math

Define the function f.

def f(x):
  return x + math.sin(x)

The main part of the program. Read the input value .

x = float(input())

Compute and print the value of the function .

print(f(x))

Python implementation — lambda function

import math

Define the function f.

f = lambda x: x + math.sin(x)

The main part of the program. Read the input value .

x = float(input())

Compute and print the value of the function .

print(f(x))