4. Inbuilt Functions and Format Specifiers (1)
4. Inbuilt Functions and Format Specifiers (1)
4. Inbuilt Functions and Format Specifiers (1)
Format Specifiers
Format Specifiers
}
Functions
In c, we can divide a large program into the basic building blocks known as function. The
function contains the set of programming statements enclosed by {}. A function can be called
multiple times to provide reusability and modularity to the C program. In other words, we
can say that the collection of functions creates a program. The function is also known
A function is a block of code that performs a specific task. A complex problem is often easier
to solve by dividing it into several smaller parts, each of which can be solved by itself.
Advantages of functions
Functions support modular programming in which a large program is divided into smaller self contained parts,
each of which has a unique identifiable purpose. This helps the program easier to write, understand, debug and
maintain.
It helps in reducing the overall size of the program as repetitive set of instructions are written only once in the
function.
Use of functions enhances the readability of a program. A big code is always difficult to read. Breaking the
code in smaller Functions keeps the program organized, easy to understand and makes it reusable.
A function can be used to create our own header file which can be used in any number of programs i.e. the
reusability.
In C, a function can call itself again, this is known as recursion. Using recursion many calculations can be
done very easily.
Classification of functions
Functions can be classified broadly in two categories: Library functions (or in-built functions) and user-defined
functions.
Library Functions
Library functions are those functions which are already defined in C library, example printf(), scanf(), strcat()
etc. The programmers need to include appropriate header files to use these functions. These are already
There functions are already defined in the C compilers. They are used for String handling, I/O operations, etc.
These functions are defined in the header file. To use these functions in a program particular header file in
for(i=0;i<num;i=i+j)
void main() {
{ if((i*i)>num)
float i,j; {
float num; i=i-j;
j=0.1; break;
clrscr(); }
}
scanf("%f",&num); printf(“Square root
of the number is %.2f",i);
Program of Square root with using Inbuilt Function
void main() */
{
int x,f;
scanf("%d",&x);
f=sqrt(x);
printf("%d",f);
getch();