C语言中预定义的函数有哪些?!
功能大致分为两种类型,如下所示-
预定义功能
用户定义函数
预定义(或)库函数
这些函数已经在系统库中定义。
程序员将重用系统库中已经存在的代码来编写无错误代码。
但是要使用库函数,用户必须了解函数的语法。
示例-
sqrt()函数在math.h库中可用,其用法是-
y= sqrt (x) x number must be positive eg: y = sqrt (25) then ‘y’ = 5
printf()存在于stdio.h库中。
clrscr()存在于conio.h库中。
示例
下面给出的是预定义函数sqrt、printf、conio上的C程序-
#include输出结果#include #include main ( ){ int x,y; clrscr ( ); printf ("enter a positive number"); scanf (" %d", &x) y = sqrt(x); printf("squareroot = %d", y); getch(); }
您将看到以下输出-
Enter a positive number 25 Squareroot = 5
考虑一些更多的预定义功能-
Cbrt(x):x的立方根
Log(x):x底e的自然对数
Ceils(x):将x舍入为不小于x的较小整数
Pow(x,y):x的y次方…………
示例
以下是使用预定义函数的C程序-
#include输出结果#include main ( ){ int x,y,z,n,k,p,r,q; printf ("输入x和n值:"); scanf (" %d%d", &x,&y) y=cbrt(x); z=exp(x); k=log(x); p=ceil(x); q=pow(x,r); printf("cuberoot = %d", y); printf("exponent value = %d",z); printf("logarithmic value = %d", k); printf("ceil value = %d", p); printf("power = %d", q); getch(); }
输出如下-
输入x和n值:9 2 cuberoot = 2 exponent value = 8103 logarithmic value = 2 ceil value = 9 power = 81