Math calculation တွေအတွက် <math.h> header ထဲမှာ အသုံးဝင်တဲ့ function အများကြီးရှိပါတယ်။ Square root, rounding, power, trigonometry စတာတွေကို ကိုယ်တိုင် formula ရေးစရာမလိုဘဲသုံးနိုင်ပါတယ်။
c
#include <stdio.h>
#include <math.h>
int main() {
printf("Square root: %.1f
", sqrt(16));
printf("Rounded: %.0f
", round(2.6));
printf("Power: %.0f", pow(4, 2));
return 0;
}sqrt(16) က 16 ရဲ့ square root ကိုတွက်ပါတယ်။ round(2.6) က အနီးဆုံး whole number ကိုပြန်ပေးပြီး pow(4, 2) က 4 power 2 ကိုတွက်ပါတယ်။
You should see
Square root: 4.0 Rounded: 3 Power: 16Info
Linux GCC မှာ math library link လုပ်ဖို့ gcc file.c -lm လိုနိုင်ပါတယ်။ Online compiler တော်တော်များများမှာတော့ auto handle လုပ်ပေးတတ်ပါတယ်။