Энэ удаа бидний анхны бие даалтад өгч байсан даалгавар болох С хэлний math.h толгой файлын зарим функцуудын гүйцэтгэх үүргүүдийг дэлгэрэнгүй тайлбарлаж өгье.
Жишээ програмууд гараас хувьсагчийг авахгүй, код дээрээ утгыг авсан байгаа гэдгийг анхаараарай. CTRL+F9 дарж ажиллуулсны дараа ALT+F5 дарж үр дүнг харна.
ceil() : Бодит тоон хувьсагчаас их, хамгийн ойр бүхэл тоо
double ceil(double x);
ceil() Хэрэглэсэн жишээ :
#include
#include
main()
{
printf ("2.5-iin ceil %.1lf\n", ceil (2.5));
return 0;
}
Гаралт:
2.5-iin ceil 3
floor() : Хувьсагчаас бага, хамгийн ойр бүхэл тоо
double floor(double x);
floor() ын жишээ:
#include
#include
main()
{
printf ("3.4-iin floor %.1lf\n", floor(3.4));
return 0;
}
Гаралт:
3.4-iin floor 3.0
fmod() : х-ийг у-т хуваахад гарах үлдэгдэл
( Бүхэл тооны хувьд %-ыг ашигладаг боловч үүнийг бодит тоон олонлогт хэрэглэхэд тохиромжтой )
double fmod(double x, double y);
Жишээ нь:
#include
#include
main()
{
printf ("2.5-g 2-t buhleer huvaahad %lf uldene \n", fmod(2.5,2));
return 0;
}
Гаралт:
2.5-g 2-t buhleer huvaahad 0.500000 uldene
exp() : е тоог өгсөн тоогоор зэрэг дэвшүүлнэ.
double exp(double x);
Жишээ нь:
#include
#include
main()
{
double input, output;
input = 2.0;
output = exp (input);
printf ("e-iin %lf zeregt= %lf.\n", input, output);
return 0;
}
Гаралт:
å-iin 2.000000 zeregt = 7.389056
fabs() : x-ийн абсолют утга(модуль)
double fabs(double x);
fabs()-ийг хэрэглэсэн жишээ:
#include
#include
main()
{
printf ("-3.51-iin absolute utga= %lf\n", fabs(-3.51));
return 0;
}
Гаралт:
-3.51-iin absolute utga=3.510000
frexp() : Өгсөн тооноос их, 2-ын зэрэг болдог тоо ба тэдгээрийн ноогдворыг гаргана.
Миний авсан жишээнд 10-ыг 16 буюу 2^4-д хуваахад 0.625 гарна гэдгийг үзүүлж байна.
double frexp(double x, &int хувьсагч);
Жишээ:
#include
#include
main()
{
double input, output;
int i;
input = 10.0;
output = frexp (input , &i);
printf ("%lf * 2^%d = %f\n", output, i, input);
return 0;
}
Гаралт:
0.625000 * 2^4 = 10.000000
ldexp() : Өгсөн 2 тооны 1-ийг 2-ын зэрэгтээр үржүүлж нөгөө тоог гаргана гэж ойлгож болох юм.
double ldexp(double x, int хувьсагч);
Жишээ нь:
#include
#include
main()
{
double input, output;
int i;
input = 0.50;
i = 2;
output = ldexp (input , i);
printf ("%f * 2^%d = %f\n", input, i, output);
return 0;
}
Гаралт:
0.500000 * 2^2 = 2.000000
modf() : Өгсөн тооны бүхэл ба бутархай хэсгийг олох функц.
double modf(double x, &integer);
Жишээ нь:
#include
#include
main()
{
double input, fractional_part, integer_part;
input = 3.14159265;
fractionalpart = modf (input , &integerpart);
printf ("%lf = %lf + %lf \n", input, integerpart, fractionalpart);
return 0;
}
Гаралт:
3.141593 = 3.000000 + 0.141593
pow() : Өгсөн 2 тооны нэгийг нөгөөгөөр зэрэг дэвшүүлнэ.
double pow(double x, double y);
pow() хэрэглэх жишээ:
#include
#include
main()
{
printf ("2 ^ 8 = %lf\n", pow (2,8));
return 0;
}
Гаралт:
2 ^ 8 = 256.000000
cosh(), coshl(): гиперболлог косинус
cosh(z)=(exp(z) + exp(-z)) / 2
Жишээ код:
#include "stdio.h"
#include "math.h"
main()
{
double x = 0.5;
printf("%lf-iin hyperbolic cosinus = %lf\n", x, cosh(x));
return 0;
}
Гаралт:
0.500000-iin hyperbolic cosinus = 1.127626
sinh(), sinhl()-гиперболлог синус
sinh(z)=(exp(z) - exp(-z)) / 2
Жишээ код:
#include "stdio.h"
#include "math.h"
main()
{
double x = 0.5;
printf("%lf-iin hyperbolic sinus = %lf\n", x, sinh(x));
return 0;
}
Гаралт:
0.500000-iin hyperbolic cosinus = 0.521095
tanh(), tanhl(): гиперболлог тангенс
tanh(z)=sinh(z) / cosh(z)
Жишээ код:
#include "stdio.h"
#include "math.h"
main()
{
double x = 0.5;
printf("%lf-iin hyperbolic tangens = %lf\n", x, cosh(x));
return 0;
}
Гаралт:
0.500000-iin hyperbolic tangens = 0.462117
hypot, hypotl - 2 катетын тусламжтай гипотенузыг олох функц
#include "stdio.h"
#include "math.h"
main()
{
double x = 3.0;
double y = 4.0;
printf("hypotenuse = %lf\n", hypot(x,y));
return 0;
}
hypotenuse = 5.000000
asin, asinl, acos, acosl, atan, atanl, atan2, atan2l - радианаар өгсөн өнцгийн арксинус, арккосинус, арктангенсийг олно.
Жишээ нь:
#include "stdio.h"
#include "math.h"
main()
{
double x=0.5;
printf("%lf - iin arccocinus %lf \n",x,acos(x));
}
Гаралт:
0.500000- iin arcosinus 1.047198
Жишээ нь:
#include
#include
int main(void)
{
double x = 90, y = 5;
printf("%lf - iin arctangens = %lf\n", (y / x), atan2(y, x));
return 0;
}
Гаралт:
0.055556 -iin arctangens = 0.055499
Sunday, October 12, 2008
MATH.H толгой файлын функцууд
Posted by Gansukh Batjargal at 12:02 AM
Labels: C/C++ programming























Subscribe to:
Post Comments (Atom)
3 comments:
Heregtei funktsee sudlaagui yum bish uu
jishee
hypot(x,y)
atan2(y,x)
log(x)
ed narig sudalval zugeerl baih.
Bayarllaa.
cvmka zypmga dgalgg.dgzjlgvgy ioo.htht.
Post a Comment