Вы находитесь на странице: 1из 12

CSE100

Fundamentals of Computer Programming

User Defined Functions

Prof. Kuntal Patel


Ahmedabad University
Topics to be covered

 Introduction to Functions
• Outline, Syntax
• Importance of User Defined Functions
 Categories of Functions
• Library Functions (also known as System defined function)
• User defined functions (written by programmers)
 Writing Functions in C Program
 Understanding Usage of Functions with demonstrations
Introduction to C Functions
Function
• Function is a group of statements which performs a specific
task.
• It is also known as Sub-routine or Procedure or Method.

There are two types of C functions:


• Library Functions (also known as System defined function)
• User defined functions (written by programmers)
Introduction to C Functions
Library Functions: These are functions provided by the
developer of C language. They are in-built with the C
language.

Examples of Library Functions:

• printf()
• scanf()
• getchar()
• sqrt()
• pow()
Introduction to C Functions
Library Functions – Demonstrations
/*C program to show use of sqrt() Library Functions. This program demonstrate use of
two library functions:
--> sqrt()
--> printf()
*/
#include<stdio.h>
#include<math.h>
void main()
{
float ans;
ans = sqrt(100);

printf("The square root of 100 is %f.", ans);


}
Output
The square root of 100 is 10.000000.
Introduction to C Functions
User Defined Functions: The functions developed by the
programmers or users are known as User Defined Functions.
• The names given to user defined functions must be different
from the names of Library functions.
• Note that main( ) is a special type of user defined function in C
language.

Examples of User Defined Functions:


• FindAverage()
• DisplayMenu()
• DrawLine()
• GenerateReport()
• PrintLine()
User Defined Function - Demonstrations

Reference: cprogrampracticals.blogspot.com/2016/10/c-function-with-no-arguments-and-no.html
User Defined Function - Demonstrations

Reference: http://cprogrampracticals.blogspot.com/2016/10/c-function-with-argument-and-no-return.html
User Defined Function - Demonstrations

Reference: http://cprogrampracticals.blogspot.com/2016/09/square-of-given-number-using-function.html
Introduction to Functions

 Demonstration – Activities

• C function with no arguments and no return value.

• C function with an argument and no return value.

• Square of given number using function with an argument


and a return value.
Topics covered

Key topics covered during session:

Introduction to Functions
• Importance of User Defined Functions
 Categories of Functions
• Library Functions (also known as System defined function)
• User defined functions (written by programmers)
 Writing Functions in C Program
 Understanding Usage of Functions with demonstrations
 Function - Demonstration – Activities
Useful References

• E Balagurusamy, “Programming in ANSI C”, Chapter – 9 Functions. Tata


McGraw-Hill

• http://cprogrampracticals.blogspot.com/p/function-definition-function-is-
group.html

Вам также может понравиться