Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

ฟังก์ชันสำคัญในไลบรารี math.h ภาษา C

ฟังก์คั่นคณิตศาสตร์ทั้งหมดอยู่ใน header math.h ในภาษา C

sin()

หาค่า sine ของอาร์กิวเมนต์

double sin(double a);

เช่น double a=sin(3.14/2); → a=1 (ประมาณ)

cos()

หาค่า cosine

double cos(double a);

เช่น double a=cos(3.14/2); → a=0 (ประมาณ)

tan()

หาค่า tangent

double tan(double a);

เช่น double a=tan(3.14/2);

exp()

หาค่าเลขยกกำลัง (e^x)

double exp(double a);

เช่น double a=exp(4.6);

floor()

ปัดเศษทศนิยมลง (round down)

double floor(double a);

เช่น double a=floor(93.58); → a=93

ceil()

ปัดเศษทศนิยมขึ้น (round up)

double ceil(double a);

เช่น double a=ceil(93.58); → a=94

abs()

หาค่าสัมบูรณ์ของจำนวนเต็ม

int abs(int a);

เช่น int a=abs(-6); → a=6

pow()

หาค่ายกกำลัง

double pow(double a, double b);

เช่น double x=pow(2,3) → x=8

sqrt()

หาค่ารากที่สอง

double sqrt(double a);

เช่น double x=sqrt(36); → x=6