#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.
3.50 + 2.20 = 5.70
3.50 - 2.20 = 1.30
3.50 * 2.20 = 7.70
3.50 / 2.20 = 1.59
3.50 % 2.20 = 1.30
sqrt(3.50) = 1.87
abs(2.20) = 2.20
180.00 degrees = 3.14 radians
3.14 radians = 179.91 degrees