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
這將編譯并運行你的代碼,輸出相應的結果。請注意,不同的編譯器和操作系統可能需要不同的鏈接選項。