Home > Backend Development > C++ > body text

What are the predefined functions in C language?

王林
Release: 2023-08-25 15:01:10
forward
1344 people have browsed it

What are the predefined functions in C language?

Functions are roughly divided into two categories, as follows: -

  • Predefined functions
  • User-defined functions

Predefined (or) library functions

  • These functions have been defined in the system library.

  • Programmers will reuse code already in system libraries to write error-free code.
  • But to use library functions, users must understand the syntax of the function.

Example-

  • sqrt() function is available in math.h library and its usage is-
y= sqrt (x)
x number must be positive
eg: y = sqrt (25)
then ‘y’ = 5
Copy after login
  • printf ( ) exists in the stdio.h library.
  • clrscr ( ) exists in the conio.h library.

Example

The following is a C program of predefined functions sqrt, printf, conio-

#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();
}
Copy after login

Output

You will see the following output -

Enter a positive number 25
Squareroot = 5
Copy after login

Consider some of the more predefined functions -

  • Cbrt(x): Cube root of x
  • Log(x): The natural logarithm of the base of .
  • Pow(x,y): x raised to the y power...
  • ul>
  • ExampleThe following is a C program using predefined functions-

    #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();
    }
    Copy after login

    Output

    The output is as follows-
    enter x and n values:9 2
    cuberoot = 2
    exponent value = 8103
    logarithmic value = 2
    ceil value = 9
    power = 81
    Copy after login

    The above is the detailed content of What are the predefined functions in C language?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!