C语言的数学库(math.h)提供了许多有用的数学函数,这些函数可以在实际编程中解决各种数学问题
#include<stdio.h>
#include <math.h>
double num = 9.0;
double sqrt_num = sqrt(num);
printf("Square root of %lf is %lf\n", num, sqrt_num);
double angle = 30.0; // in degrees
double radians = angle * (M_PI / 180.0); // convert to radians
double sine_value = sin(radians);
printf("Sine of %lf degrees is %lf\n", angle, sine_value);
double angle = 60.0; // in degrees
double radians = angle * (M_PI / 180.0); // convert to radians
double cosine_value = cos(radians);
printf("Cosine of %lf degrees is %lf\n", angle, cosine_value);
double base = 2.0;
double exponent = 3.0;
double result = pow(base, exponent);
printf("%lf raised to the power of %lf is %lf\n", base, exponent, result);
double num = 5.67;
double rounded_num = round(num);
printf("Rounded value of %lf is %lf\n", num, rounded_num);
double num = 5.67;
double floor_num = floor(num);
double ceil_num = ceil(num);
printf("Floor value of %lf is %lf and Ceil value is %lf\n", num, floor_num, ceil_num);
double num = -10.5;
double abs_num = fabs(num);
printf("Absolute value of %lf is %lf\n", num, abs_num);
-lm
标志)。例如,在命令行上执行以下操作:gcc your_file.c -o output_file -lm
./output_file
这将编译并运行你的代码,输出相应的结果。请注意,不同的编译器和操作系统可能需要不同的链接选项。