You are on page 1of 11

CMR ENGINEERING COLLEGE

INTRODUCTION:-

Name: M . Jaya Sai


Roll No : 238R1A12P2
Branch : IT-D
Subject : Programming for
problem solving
Topic: Introduction to fucntions
C Functions
• A function is a block of code that performs a
specific task.
• Suppose, you need to create a program to create a
circle and color it. You can create two functions
to solve this problem:
• create a circle function
• create a color function
• Dividing a complex problem into smaller chunks
makes our program easy to understand and reuse.
Types of function
There are two types of function in
C programming:
•Standard library functions
•User-defined functions
1. Standard Library Functions
Standard library functions or Simply Libraru
functions are inbuilt functions in C programming.
The prototype and data definitions of these
functions are present in their respective header
files. To use these functions we need to include
the header file in our program.
For example,
If you want to use the Printf() function, the If you try to use printf() without
header file <stdio.h> should be included including the stdio.h header
file,you will get an error.
Example: Square root using sqrt() function

OUTPUT:
Library Functions in Different Header
Files:
C Header Description
Files C Header Description
<assert.h> Program assertion functions Files

<ctype.h> Character type functions <string.h> String handling functions


<stdlib.h> Standard Utility functions
<locale.h> Localization functions
<math.h> Mathematics functions <stdio.h> Standard Input/Output
functions
<setjmp.h> Jump functions
<stdarg.h> Variable arguments handling
<time.h> Date time functions functions
<signal.h> Signal handling functions
C User-defined
functions:
A function is a block of code that performs
a specific task.
In order to make a user
defined functions we need
C allows you to define functions according to follow 3 steps:
to your need. These functions are known
1. Function prototype.
as user-defined functions.
For example:
2. Function call
Suppose, you need to create a circle and 3. Function definition or
color it depending upon the radius and function
color. You can create two functions to implementation
solve this problem:
createCircle() function
color() function
Function prototype:
A function prototype is simply the declaration of a
function that specifies function's name, parameters
and return type. It doesn't contain function body.
A function prototype gives information to the
compiler that the function may later be used in the
program.
Syntax:
Calling a function
Control of the program is transferred to the user-defined function by
calling it. In the this example, the function
Syntax of function call call is made using addNumbers(n1,
n2); statement inside the main()
function.
Function definition
Function definition contains the block of code
to perform a specific task. In our example, When a function is called, the
adding two numbers and returning it. control of the program is
Syntax of function definition transferred to the function
definition. And, the compiler starts
executing the codes inside the body
of a function.
Program:
OUTPUT:

You might also like