2864. Function tabulation

 

Write a program that displays a table of values for the function

y = 3 * sin(x)

over the interval from a to b inclusive, with a step size of h.

 

Input. Three real numbers a, b and h.

 

Output. For each value of x in the given interval, print two numbers x and y on a separate line, in ascending order of x. Both numbers must be printed with three decimal places.

 

Sample input

Sample output

1 2 0.5

1.000 2.524

1.500 2.992

2.000 2.728

 

 

SOLUTION

loops

 

Algorithm analysis

Iterate over the values of x from a to b with a step of h. For each value of x, print a pair of numbers: x and 3 * sin(x).

 

Algorithm implementation

The function f returns the value 3 * sin(x).

 

double f(double x)

{

  return 3 * sin(x);

}

 

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

 

scanf("%lf %lf %lf", &a, &b, &h);

 

Iterate over the values of x from a to b with a step of h. For each value of x, we print a pair of numbers: x and f(x).

 

for (x = a; x <= b; x += h)

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