c++函数大全带程序文档格式.docx
《c++函数大全带程序文档格式.docx》由会员分享,可在线阅读,更多相关《c++函数大全带程序文档格式.docx(36页珍藏版)》请在冰豆网上搜索。
atan
doubleatan(doublex);
计算tan^-1(x)的值.
切记单位为弧度,如果想输入为度数,请转换.方法:
弧度=度数*3.14159/180
doubleresult;
doublex=0.5;
result=atan(x);
Thearctangentof%lfis%lf"
x,result);
return(0);
/////////////////////////////////////////////
COS
cos
doublecos(doublex);
计算cos(x)的值.余弦函数.
x的单位为弧度.切记单位为弧度,如果想输入为度数,请转换.方法:
弧度=度数*3.14159/180
intmain(void)
result=cos(x);
Thecosineof%lfis%lf
"
COSH
cosh
doublecosh(doublex);
计算x的双曲余弦cosh(x)的值.
result=cosh(x);
Thehyperboiccosineof%lfis%lf"
//////////////////////////////////////////
EXP
exp
doubleexp(doublex);
求e的x次幂
计算结果.幂的值
x指数
doublex=4.0;
result=exp(x);
'
e'
raisedtothepowerof%lf(e^%lf)=%lf"
x,x,result);
FABS
fabs
doublefabs(doublex);
求x的绝对值.
floatnumber=-1234.0;
%fabsolutevalue:
%f"
number,fabs(number));
FLOOR
floor
doublefloor(doublex);
求出不大于x的最大整数.
该整数的双精度实数
doublenumber=123.54;
doubledown,up;
down=floor(number);
up=ceil(number);
originalnumber%10.2lf"
number);
numberroundeddown%10.2lf"
down);
numberroundedup%10.2lf"
up);
/////////////////////////////////////////////////
FMOD
fmod
doublefmod(doublex,doubley);
求整除x/y的余数
返回余数的双精度数.x/y的余数值.
doublex=5.0,y=2.0;
result=fmod(x,y);
Theremainderof(%lf/%lf)is%lf"
x,y,result);
////////////////////////////////////////////////
FREXP
frexp
doublefrexp(doubleval,int*eptr);
把双精度数val分解为数字部分(尾数)x和以2为底的指数n,即val=x*2^n,n存放在eptr指向的变量中.
返回数字部分x0.5<
=x且x<
1
val待分解的数
doublemantissa,number;
intexponent;
number=8.0;
mantissa=frexp(number,&
exponent);
Thenumber%lfis"
number);
%lftimestwotothe"
mantissa);
powerof%d"
exponent);
LOG
log
doublelog(doublex);
求logeX(e指的是以e为底),即计算x的自然对数(lnX)
doublex=8.6872;
result=log(x);
Thenaturallogof%lfis%lf"
//////////////////////////////////////////////
MODF
每天学习一个C++函数——modf(2011-5-6)
modf
doublemodf(doubleval,double*iptr);
把双精度数val分解为整数部分和小数部分,把整数部分存到iptr指向的单元.
val的小数部分
doublefraction,integer;
doublenumber=100000.567;
fraction=modf(number,&
integer);
Thewholeandfractionalpartsof%lfare%lfand%lf"
number,integer,fraction);
///////////////////////////////////////////////
RAND
rand
intrand(void);
产生-90到32767间的随机整数(0到0x7fff之间)
随机整数
inti;
printf("
Tenrandomnumbersfrom0to99"
);
for(i=0;
i<
10;
i++)
%d"
rand()%100);
SIN
sin
doublesin(doublex);
计算sinx的值.正弦函数
弧度=度数*3.149/180
doubleresult,x=0.5;
result=sin(x);
Thesin()of%lfis%lf"
/////////////////////////////////////////////////////
SINH
sinh
doublesinh(doublex);
计算x的双曲正弦函数sinh(x)的值.
result=sinh(x);
Thehyperbolicsin()of%lfis%lf"
///////////////////////////////////////////////////////////
SQRT
sqrt
doublesqrt(doublex);
计算x的开平方.
x应>
=0.
doublex=4.0,result;
result=sqrt(x);
Thesquarerootof%lfis%lf"
////////////////////////////////////////////////////
TAN
tan
doubletan(doublex);
计算tan(x)的值,即计算角度x的正切数值
=0切记单位为弧度,如果想输入为度数,请转换.方法:
doubleresult,x;
x=0.5;
result=tan(x);
Thetanof%lfis%lf"
//////////////////////////////////////////////////
TANH
tanh
doubletanh(doublex);
计算x的双曲正切函数tanh(x)的值.
result=tanh(x);
Thehyperbolictangentof%lfis%lf"
//////////////////////////////////////////////////////////
POW
pow
doublepow(doublex,doubley);
计算以x为底数的y次幂,即计算x^y的值.
x底数,y幂数
doublex=2.0,y=3.0;
%lfraisedto%lfis%lf"
x,y,pow(x,y));
////////////////////////////////////////////////////////
ISALPHA
isalpha
intisalpha(intch);
检查ch是否是字母.
是字母或返回1,否则返回0.
所属文件<
ctype.h>
ISCNTRL
iscntrl
intiscntrl(intch);
检查ch是否控制字符(其ASCII码在0和0x1F之间,数值为0-31).
是返回1,否则返回0.
///////////////////////////////////////////////////
ISDIGIT
isdigit
intisdigit(intch);
检查ch是否是数字(0-9).
无范例
ISGRAPH
isgraph
intisgraph(intch);
检查ch是否可打印字符(其ASCII码在ox21到ox7E之间),不包括空格.
ISLOWER
islower
intislower(intch);
检查ch是否小写字母(a-z).
ISPRINT
isprint
intisprint(intch);
检查ch是否是可打印字符(包括空格),其ASCII码在ox20到ox7E之间
//////////////////////////////////////////////////////
ISPUNCT
ispunct
intispunct(intch);
检查ch是否是标点字符(不包括空格),即除字母,数字和空格以外的所有可打印字符.
ISSPACE
isspace
intisspace(intch);
检查ch是否是空格符和跳格符(控制字符)或换行符.
ISUPPER
isupper
intisupper(intch);
检查ch是否是大写字母(A-Z).
ISXDIGIT
isxdigit
intisxdigit(intch);
检查ch是否是一个16进制数学字符(即0-9,或A-F,或a-f).
是返回1,否则返回0.
SYRCAT
strcat
char*strcat(char*str1,char*str2);
把字符串str2接到str1后面,str1最后的'
\0'
被取消.
str1
string.h>
范例:
chardestination[25];
char*blank="
"
*c="
C++"
*Borland="
Borland"
;
strcpy(destination,Borland);
strcat(destination,blank);
strcat(destination,c);
%s"
destination);
STRCHR
strchr
char*strchr(char*str,intch);
str;
找出str指向的字符串中第一次出现字符ch的位置.
返回指向该位置的指针,如找不到,则返回空指针.
str待搜索的字符串,ch查找的字符
charstring[15];
char*ptr,c='
r'
strcpy(string,"
Thisisastring"
ptr=strchr(string,c);
if(ptr)
Thecharacter%cisatposition:
c,ptr-string);
else
Thecharacterwasnotfound"
STRCMP
strcmp
intstrcmp(char*str1,char*str2);
比较两个字符串str1,str2.
str1<
str2,返回负数str1=str2,返回0str1>
str2,返回正数.
范