Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
825 B
3
Indexable
Never
#include <stdio.h>
#include <math.h>
#define PI 3.1415

double degrees_to_radians(double degrees) {
    return degrees * PI / 180.0;
}

double f(double x) {
	float ar = x * PI / 180.0;
    return sin(ar) + 1;
}

double forward_difference_derivative(double x, double h) {
    double x_rad = degrees_to_radians(x);
    double fx = f(x_rad);
    double fx_plus_h = f(x_rad + h);
    return (fx_plus_h - fx) / h;
}

int main() {
    double x_degrees, h;
    printf("Enter the value of x in degrees: ");
    scanf("%lf", &x_degrees);

    printf("Enter the step size h: ");
    scanf("%lf", &h);

    double derivative = forward_difference_derivative(x_degrees, h);

    printf("The derivative of f(x) = sin(x) + 1 at x = %.2lf is approximately %.4lf\n", x_degrees, derivative);

    return 0;
}