material/program/c_cpp/universal/常用函数.txt
2025-02-27 22:25:34 +08:00

35 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

abs(x); //求x的绝对值 e.g.abs(-5)=5
fabs() //实数绝对值
a=clock();测量从程序开始到目前的时间并把值给a。单位毫秒级
exp(x); //求x的自然指数e^x e.g.exp(1)=2.718282
floor(x); //向下取整
ceil(x); //向上取整
log(x); //求实数x的自然数对数 e.g.log(1)=0
pow(x,y); //计算x^y,输出为双精度实数 e.g.pow(2,3)=8
sqrt(x); //求x的平方根 e.g.sqrt(25)=5
str.length();获取字符串长度(只能用在字符串string b="123456789"//字符串定义 初始化。
str.size();
strlen(str);获取字符数组长度(只能用在字符数组)。
abort() //终止程序运行 不能结束工作
exit() //终止程序运行 做结束工作
max(a,b) //两数中最大
min(a,b) //两数中最小
swap(a,b) //交换两个类型相同的变量
sort(数组名+起始单元,数组名+结束单元排序方法cmp倒)
sort(a,a+n);//sort默认为升序
int cmp(int a,int b)
{
return a>b;
}
Sleep(s时间);//程序运行到此处时暂停s毫秒注意大小写需调用头文件#include<windows.h>
void color(const unsigned short textColor) //颜色字函数
{
if(textColor>=0&&textColor<=15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),textColor);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
}