Chapter 7: Function.

Slides:



Advertisements
Similar presentations
User Defined Functions
Advertisements

Functions Function: The strength of C language is to define and use function. The strength of C language is that C function are easy to define and use.
Spring Semester 2013 Lecture 5
Chapter Five Functions
An Introduction to Programming with C++ Fifth Edition
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
Chapter 6: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
Chapter 6: User-Defined Functions I
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
 Introduction Introduction  Types of Function Types of Function  Library function Library function  User defined function User defined function 
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Subprograms1 THE CALL STATEMENT (chp. 16) Purpose: a calling that executes another program; allows portions of code to be treated as a “black box”. Syntax.
CPS120: Introduction to Computer Science Functions.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Chapter 8: Arrays and Functions Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
FUNCTIONS IN C++. DEFINITION OF A FUNCTION A function is a group of statements that together perform a task. Every C++ program has at least one function,
1 Program Planning and Design Important stages before actual program is written.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
User defined functions
FUNCTIONS A function is a set of instructions that can perform a specific task accordingly. A function is a program that performs a specific task according.
Definition of function Types of Function Built-in User Defined Catagories of Function No argument No return value Argument but No return value No argument.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Manish K Parmar PGT (CS) K V VVNagar Thursday, December 24, 2015 Lesson on USER DEFINED FUNCTION IN C++ Presented by Manish K Parmar PGT Computer Science.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
Modularity using Functions Chapter 4. Modularity In programming blocks of code often can be "called up" and reused whenever necessary, for example code.
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
FUNCTION Functions is a sub-program that contains one or more statements and it performs some task when called.
1 ICS103 Programming in C Lecture 8: Functions I.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Programming Fundamentals Enumerations and Functions.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Announcements. Practice questions, with and without solutions will be uploaded by Friday 5 th November, make sure to check them before the weekend \\netstorage\Subjects\ITCA-b\Exam.
Tarik Booker CS 242. What we will cover…  Functions  Function Syntax  Local Variables  Global Variables  The Scope of Variables  Making Functions.
Chapter 9: Value-Returning Functions
Topics Introduction to Functions Defining and Calling a Void Function
Chapter 6: User-Defined Functions I
Lesson #6 Modular Programming and Functions.
Lesson #6 Modular Programming and Functions.
Lecture 2 Introduction to Programming
Function There are two types of Function User Defined Function
Module 4 Functions – function definition and function prototype.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
Deitel- C:How to Program (5ed)
Functions in C Mrs. Chitra M. Gaikwad.
Microsoft Access Illustrated
User-Defined Functions
Lesson #6 Modular Programming and Functions.
Functions Declarations CSCI 230
User Defined Functions
Functions I Creating a programming with small logical units of code.
1) C program development 2) Selection structure
CSCE 206 Lab Structured Programming in C
Chapter 6: User-Defined Functions I
Chapter 9: Value-Returning Functions
Lesson #6 Modular Programming and Functions.
Topics Introduction to Functions Defining and Calling a Function
Chapter 5: Selection Statement
In C Programming Language
Functions Imran Rashid CTO at ManiWeber Technologies.
CSCE 206 Lab Structured Programming in C
Functions I Creating a programming with small logical units of code.
CPS125.
Presentation transcript:

Chapter 7: Function

Function: Definition Building block of C program. Group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. We can divide up your code into separate functions. How we divide up your code among different functions is up to us, but logically the division is such that each function performs a specific task. Eg. printf(), scanf(), sqrt(), pow()

Functions Definition

Function Definition Contd..

Calling the function Definition of what the function has to do is given while creating function To use a function, we will have to call that function to perform the defined task. When a program calls a function, the program control is transferred to the called function. A called function performs a defined task and when its return statement is executed or when its function-ending closing brace is reached, it returns the program control back to the main program. To call a function, we simply need to pass the required parameters along with the function name, and if the function returns a value, then you can store the returned value.

Example 1: Program to find sum of number

Example 2: program to find greatest number between two number

Example 3: Program to check whether a number is prime or not Program to generate series of nth prime number Program to generate prime number between two nymbers

Function Prototype In some compiler if we are going write user defined function after main() we have to prototype the function. Syntax: datatype function name(date_type, ……..) Provides following information to function The name of the function Return data type Number of arguments that function accepts

Limitation of Return Returns only one value at a time Invalid return return(a+2, b) return(x, y)

Advantages of Function Avoid repetition of codes. Increases program readability. Divide a complex problem into simpler ones. Reduces chances of error. Modifying a program becomes easier by using function. Easy to debug

Categories of Function Library functions Built in function, already written, compiled and placed in c library Eg: printf(), scanf(), sqrt(), pow() …. User defined function Defined and used by programmer according to their requirement

Categories of User Defined Function Depending upon the number of arguments and return types used defined function can be categorized as Function returning value and passing arguments Function returning no value by passing arguments Function returning value and passing no arguments Function returning no value and passing no arguments

Function returning value and passing arguments

Function returning no value by passing arguments

Function returning value and passing no arguments

Function returning no value and passing no arguments Left to you!!!!!!!