卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章64334本站已运行4115

C语言中的预定义函数有哪些?

C语言中的预定义函数有哪些?

函数大致分为两类,如下: -

  • 预定义函数
  • 用户定义函数

预定义(或)库函数

  • 这些函数已在系统库中定义。

  • < p>程序员将重用系统库中已有的代码来编写无错误的代码。

  • 但是要使用库函数,用户必须了解函数的语法。

示例 -

  • 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<stdio.h>
#include<conio.h>
#include<math.h>
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次方……...
  • Pow(x,y):x的y次幂……
  • ul>

    示例

    以下是使用预定义函数的 C 程序 -

    #include<stdio.h>
    #include<math.h>
    main ( ){
       int x,y,z,n,k,p,r,q;
       printf ("enter x and n values:");
       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();
    }

    输出

    输出如下 -

    enter x and n values:9 2
    cuberoot = 2
    exponent value = 8103
    logarithmic value = 2
    ceil value = 9
    power = 81

卓越飞翔博客
上一篇: 解决golang报错:invalid type assertion: 'x'.(T) (non-interface type U on left)
下一篇: 解析PHP错误日志并生成对应错误报错提示的方法

相关推荐

留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏