Thuta Learning
ရှာဖွေရန်
IntermediateProgrammingbeginner

Math Functions

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

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: 16

Info

Linux GCC မှာ math library link လုပ်ဖို့ gcc file.c -lm လိုနိုင်ပါတယ်။ Online compiler တော်တော်များများမှာတော့ auto handle လုပ်ပေးတတ်ပါတယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • <math.h> မထည့်ဘဲ math function သုံးရင် warning/error တွေထွက်နိုင်ပါတယ်။
Math Functions | Thuta Learning