#include <stdio.h>
#include <math.h>
int main(void) {
// Perform some arithmetic operations
double a = 3.5;
double b = 2.2;
printf("%.2f + %.2f = %.2f\n", a, b, a + b);
printf("%.2f - %.2f = %.2f\n", a, b, a - b);
printf("%.2f * %.2f = %.2f\n", a, b, a * b);
printf("%.2f / %.2f = %.2f\n", a, b, a / b);
printf("%.2f %% %.2f = %.2f\n", a, b, fmod(a, b));
// Calculate the square root and absolute value
printf("sqrt(%.2f) = %.2f\n", a, sqrt(a));
printf("abs(%.2f) = %.2f\n", b, fabs(b));
// Convert degrees to radians and vice versa
double degrees = 180.0;
printf("%.2f degrees = %.2f radians\n", degrees, deg2rad(degrees));
double radians = M_PI;
printf("%.2f radians = %.2f degrees\n", radians, rad2deg(radians));
return 0;
}
This program demonstrates how to use the following math functions:
fmod
: Calculates the floating-point remainder of a division operation.sqrt
: Calculates the square root of a number.fabs
: Calculates the absolute value of a number.deg2rad
: Converts an angle from degrees to radians.rad2deg
: Converts an angle from radians to degrees.
0 Comments