Let the mathematical function f be defined by $$f(x) = (2x + 3)(3x^2 + 2)$$
- Write a program C that calculates the image by f of a number entered on the keyboard.
- An approximation of the derivative f' of the function f is given at each point x, for h small enough (close to 0), by : $$f'(x)\simeq\frac{f(x+h)-f(x)}{h}$$
Write a C program that calculates and displays an approximation of the derivative of f at a point x entered at the keyboard. You can enter the parameter h on the keyboard.
Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
int main()
{
double x;
double h;
printf("Enter X: ");
scanf("%lf", &x); // -0.1
printf("Enter h: ");
scanf("%lf", &h); // 0.000000000001
printf("f(%.2lf)=%.2lf\n",x, (2*x + 3)*(3*x*x + 2) );
printf("f'(%.2lf)=%.2lf\n",x, ( ( (2*(x+h) + 3)*(3*(x+h)*(x+h) + 2) - (2*x + 3)*(3*x*x + 2)) / h) );
return 0;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Insert a value into a sorted array