Lecture 9 - C Functions

Size: px
Start display at page:

Download "Lecture 9 - C Functions"

Transcription

1 ECET 264 C Programming Language with Applications Lecture 9 C Functions Paul I. Lin Professor of Electrical & Computer Engineering Technology Lecture 9- Prof. Paul I. Lin 1 Lecture 9 - C Functions C Functions Function Prototypes Function Definitions Function Calls by Value Function Calls by Reference Examples Example 9-1: Square Function Example 9-2: String Length Function Example 9-3: Function cube() Example 9-4: Max Function Example 9-5: Add1() Function Example 9-6: Averaging Elements in an Array Example 9-7: Call By Reference Swap() Example 9-8: Testing Functions Summary Lecture 15 - Prof. Paul I. Lin 2 1

2 C Functions Every C program must include a function called main() that begins the execution of the program. Functions allow programmers to modularize a program Function Prototypes C Functions must be declared before they are used A C function normally requires a definition of function prototype that consists of the following elements: Output parameter (Return type), function name, input parameters enclosed by a pair of parenthesis A function prototype offers a view of how to use the desired function, passing input arguments, receive a return value with known type. Lecture 15 - Prof. Paul I. Lin 3 Function Prototypes C Functions (Continue) All function prototypes are save in their specific header files with.h as extension Header files for C s standard library function can be included in a user program using the following syntax #include <stdio.h> #include <math.h> For example, as discussed earlier, the stdio.h is a header file which contains all standard I/O function definitions. The function prototypes including printf(), scanf(), etc., are save on this header file Lecture 15 - Prof. Paul I. Lin 4 2

3 C Functions (continue) Function Body A C function normally includes the following elements: An output parameter (Return type) Function name Input parameters enclosed by a pair of parenthesis, begin brace, local variable definitions, statements, and a return with the type that matches the Return type, and end brace. The input and output parameters provide the means for passing information in and out of a function Function s parameters are also treated as local variables of that function All variables defined in function definitions are considered local variables Lecture 15 - Prof. Paul I. Lin 5 C Functions (continue) Functions support structured programming and offer the following advantages Hierarchical flow control Break large tasks into smaller ones Easy to maintain Improve software reusability Main() Worker1 Worker2 Worker3 Worker4 Worker5 Lecture 15 - Prof. Paul I. Lin 6 3

4 C Functions (continue) Categories of C functions Standard library functions User defined functions Developed in house Purchased from other companies Windows API functions GUI-based Event-driven Lecture 15 - Prof. Paul I. Lin 7 Function Prototypes Important features of function prototypes: A function prototype tells the C compiler the type of data to be returned by the function the number of parameters the function expects to receive the types of the parameters the order in which these parameters are expected. Lecture 15 - Prof. Paul I. Lin 8 4

5 Function Prototypes (continue) The compiler uses function prototypes to validate function calls Detect syntax error - when a function call does not match the function prototype Coercion of arguments Force invalid arguments type become an appropriate type Providing documentation of functions to programmers and readers Lecture 15 - Prof. Paul I. Lin 9 Defining Functions type function_name (formal parameters) /* variable declarations */ type val; statements; return (val); Return type of function: Out Parameters or Return a value with specified data type Only one value can be returned When there is a need to get more than one value returned, use call by reference A function that does not return anything should have a type "void" Lecture 15 - Prof. Paul I. Lin 10 5

6 Defining Functions (cont.) Defining functions or Function prototyping type function_name (formal parameters) Return value type int square(int y); Argument name Function name Parameter type Function_name Function s name formal parameters For receiving information(arguments) Lecture 15 - Prof. Paul I. Lin 11 Function Call Functions can be called by any other functions, but can not be nested with other functions. Functions are invoked by a function call, all variables and parameters defined in function definitions are local variables of that function The parameters provide the means for communicating information between functions Lecture 15 - Prof. Paul I. Lin 12 6

7 Function Call (Invocation) f_name (parameters); /* if no return value is expected */ n = f_name(parameters); /* return a value */ Function call s execution sequence: Save the return address Pass arguments (through the stack) and transfer control to the function Function return a value or simply return the control to the caller Lecture 15 - Prof. Paul I. Lin 13 Example 9-1: Square Function #include <stdio.h> int square(int y) /* function prototype */ int main() int x; for (x=1; x <= 10; x++) printf( %d, square(x)); printf( \n ); return 0; call square function return Return value type void square(int y) printf( %f, square(x) Argument type /*function square definition */ int square(int y); int square(int y) Function name Parameter name return y * y; Lecture 15 - Prof. Paul I. Lin 14 7

8 Example 9 2: strlen() Function Problem Statement: Write a C function that examines and returns the length of a given string or character array. Analysis Return type integer is sufficient since most strings have limited length Function name strlen, a meaningful name Input parameter char s[] a character array, with s[], or any meaningful name such as string[] Lecture 15 - Prof. Paul I. Lin 15 Example 9 2: strlen() Function (cont.) Solution and Function Documentation /* Function name: strlen() * Input: a character array of any length * Returned: an integer containing the length of the array * / int strlen(char s[]) /*function definition */ int n = 0; while (s[ n++]!= '\0'); return n; Lecture 15 - Prof. Paul I. Lin 16 8

9 Example 9 2: strlen() Function (cont.) How to invoke the strlen() function Assume that a function named strlen() for checking the length of any arbitrary string of any length is available for use. It s function prototypes is int strlen (char s[ ]); The function body of the strlen() is as shown below: int strlen(char s[ ]) int n = 0; while (s [n++]!= '\0'); return n; Lecture 15 - Prof. Paul I. Lin 17 Example 9 2: strlen() Function (cont.) Example: How to invoke the strlen() function /* strlen_test.c */ #include <stdio.h> int strlen (char s[ ]); void main() int strlen(char s[ ]) int len; char string [80]; int n = 0; gets (string); while (s [n++]!= \0 ); len = strlen (string); return n; Lecture 15 - Prof. Paul I. Lin 18 9

10 Example 9 2: strlen() Function (cont.) /* test_strlen.c */ #include <stdio.h> int strlen(char s[]); /* list function prototypes */ void main() int len; char string[80]; while(1) puts("enter a string, Ctrl-C to Exit"); gets(string); len = strlen(string); printf("the length of string[%s] is %d.\n", string, len); /* Function name: strlen() * Input: a character array of * any length. * Returned: an integer * containing the length of the * array */ int strlen(char s[]) /*function definition */ int len = 0; while (s[len++]!= '\0'); return len; Lecture 15 - Prof. Paul I. Lin 19 Example 9 2: strlen() Function (cont.) OUTPUT: Enter a string, Ctrl-C to Exit C program The length of string[c program] is 10. Enter a string, Ctrl-C to Exit ECET264 The length of string[ecet264] is 8. Enter a string, Ctrl-C to Exit 1 The length of string[1] is 2. Enter a string, Ctrl-C to Exit The length of string[] is 1. Enter a string, Ctrl-C to Exit Lecture 15 - Prof. Paul I. Lin 20 10

11 Example 9-3: Function cube() A math function cube() compute x^3: Function Prototype saved in a specific header file along with other related function prototypes. float cube(float x); /* saved in xyz_meth.h */ Function body saved in a specific C file, xyz_math.c along with other related C functions float cube(float x) /* saved in xyz_math.c */ return (x*x*x); Lecture 15 - Prof. Paul I. Lin 21 Example 9-3: Testing Cube( ) Function (cont.) Problem Statement: You are asked to test the cube( ) function to meet the requirements of software quality. Analysis: The two system defined functions: scanf( ) and printf( ) will be needed to ask user inputs for testing, and display the testing results. Knowing that all system library functions are precompiled into the object file, therefore no source file will be needed. The IDE will link the specified system library functions during the building phase of the executable program. Lecture 15 - Prof. Paul I. Lin 22 11

12 Example 9-3: Testing Cube( ) Function (cont.) Analysis: We need to obtain a copy of the function prototype, and put the line as shown in xyz_math.h which may contain other math related function prototypes. float cube(float x); /* saved in xyz_meth.h */ We also need to have the source code and place it in xyz_math.c along with other math functions float cube(float x) /* saved in xyz_math.c */ return (x*x*x); Lecture 15 - Prof. Paul I. Lin 23 Example 9-3: Testing Cube( ) Function (cont.) /* cube_test.c */ #include <stdio.h> #include "xyz_math.h" void main() float n, result; while(1) printf("\nplease enter a number for computing n^3 or Crtl C to exit: "); scanf("%f", &n); result = cube(n); /* Function Call */ printf("%f^3 = %f\n", n, result); return; #include "xyz_math.c" Lecture 15 - Prof. Paul I. Lin 24 12

13 Example 9-3: Testing Cube( ) Function (cont.) OUTPUT: Please enter a number for computing n^3 or Crtl C to exit: ^3 = Please enter a number for computing n^3 or Crtl C to exit: ^3 = Please enter a number for computing n^3 or Crtl C to exit: ^3 = Please enter a number for computing n^3 or Crtl C to exit: ^3 = Please enter a number for computing n^3 or Crtl C to exit: Lecture 15 - Prof. Paul I. Lin 25 Example 9-3: Testing Cube( ) Function (cont.) /* cube_test.c */ #include <stdio.h> #include "xyz_math.h" void main() float n, result; while(1) printf("\nplease enter a number for computing n^3 or Crtl C to exit: "); scanf("%f", &n); result = cube(n); /* Function Call */ printf("%f^3 = %f\n", n, result); printf("%e^3 = %e\n", n, result); /* %e for higher accuracy */ return; #include "xyz_math.c" Lecture 15 - Prof. Paul I. Lin 26 13

14 Example 9-3: Testing Cube( ) Function (cont.) NEW OUTPUT SCREEN Please enter a number for computing n^3 or Crtl C to exit: ^3 = ^3 = e-013 Please enter a number for computing n^3 or Crtl C to exit: ^3 = ^3 = e-016 Please enter a number for computing n^3 or Crtl C to exit: Lecture 15 - Prof. Paul I. Lin 27 Example 9-4: max() Function /* Function Prototypes */ unsigned long fac(int); int max(int a, int b);.. void main(void) int x, y, z; x = 10; y = 100; z = 1000; z = max(1, 2); /* Function call */ x = max(y, z); /* Function Bodies */ int max (int a, int b) return ((a > b)? a: b;) Lecture 15 - Prof. Paul I. Lin 28 14

15 Example 9 5: Add1 Function Example: A routine may use the formal arguments as temporary local variables. The variable "number" in the add1() function is also used a local variable. int add1(int number); void main(void) int add1(int number) int i = 5; int out_number; int j; out_number = number + 1;. return (out_number);. j = add1(i); /* after this i is still holds 5*/. Lecture 15 - Prof. Paul I. Lin 29 Example 9-6: Averaging Elements in an Array Problem Statement: Write a function that computes the average temperature of a temperature array. This is a floatingpoint number array which holds temperature obtained from a temperature sensor. Analysis Return type float or double Function name sumtemparray Input parameters float temp[] array, and the variable size of int type for the array elements Lecture 15 - Prof. Paul I. Lin 30 15

16 Example 9-6: Averaging Elements in an Array (cont.) Solution: float avgtemparray (float temp[], int size) int i = 0; float sum = 0.0; while (i < size) sum += temp[i]; i++; return (sum/size); Lecture 15 - Prof. Paul I. Lin 31 Example 9-6: Averaging Elements in an Array (cont.) /* sumarray.c */ #include <stdio.h> float avgtemparray(float temp[], int size); void main() float tempsum; int len; float tempsensor[10] = 67.3, 68.0, 68.2, 68.5, 68.4, 69.0, 65.0, 72.0, 69.2, 65.3; len = sizeof(tempsensor)/sizeof(float); printf("number of elements in the array tempsensor[] is %d.\n", len); tempavg = avgtemparray(tempsensor, len); printf("the average temperature is %5.2f degree F.\n", tempavg); float avgtemparray (float temp[], int size) int i = 0; float sum = 0.0; while (i < size) sum += temp[i]; i++; return (sum/size); Lecture 15 - Prof. Paul I. Lin 32 16

17 Example 9-6: Averaging Elements in an Array (cont.) Output: Number of elements in the array tempsensor[] is 10. The average temperature is degree F. Press any key to continue Lecture 15 - Prof. Paul I. Lin 33 Call By Value and By Reference Call By Value Most C functions are written as call-byvalue functions When arguments are passed by value, a copy of the argument s value is made and passed to the called function. The original value can not be changed Only one value can be returned Lecture 15 - Prof. Paul I. Lin 34 17

18 Call By Value and By Reference (continue) Call By Reference Reference refers to a memory address of the argument The operator & or pointer are normally used for passing address(es) It allows the access of a block of data When an argument is passed by reference, the caller actually allows the called function to modify the original variable s value. Lecture 15 - Prof. Paul I. Lin 35 Call By Value and By Reference (cont.) Call By Reference in C is accomplished by the following necessary steps: 1. Declare function parameter(s) as pointer(s) types. 2. Use the dereferenced pointer in the function body to access the values of variables. 3. Pass addresses as arguments when the function is called. Lecture 15 - Prof. Paul I. Lin 36 18

19 Example 9 7: A Call-By-Reference swap() Function Example: call by reference. The function swap() accepts two pointers and physically exchange the values of variables x and y. #include <stdio.h> void swap(int *x, int *y) void swap(int *x, int *y); void main(void) int temp; /* get the value at address x */ int x, y; temp = *x; x = 10; *x = *y; y = 20; *y = temp; printf("x = %d, y = %d\n", x, y); printf("&x = %d, &y = %d\n", &x, &y); swap(&x,&y); /* call the function swap() */ printf("x = %d, y = %d\n", x, y); printf("&x = %d, &y = %d\n", &x, &y); Lecture 15 - Prof. Paul I. Lin 37 Example 9-8: Testing Functions Problem statement: You are given a func1.c file which contains three functions: int min(int a, int b); int max(int a, int b); double power(float x, int n); And you are asked to test and document the functions and testing results. Analysis: We arrange the functions and the main in the order as listed: - Function prototypes - Main drivers and testing data setup - Function bodies at the end Lecture 15 - Prof. Paul I. Lin 38 19

20 Example 9-8: Testing Functions /* func1_test.c */ #include <stdio.h> int min(int a, int b); int max(int a, int b); double power(float x, int n); /* driver for testing functions */ void main() int x, y, z; double p, w; x = 10; y = 20; z = min(x, y);printf("min = %d\n", z); z = max(x, y);printf("max = %d\n", z); Lecture 15 - Prof. Paul I. Lin 39 Example 9-8: Testing Functions (cont.) w = 0; p = power(w, 3);printf("power(0,3) = %lf\n", p); w = -0.1; p = power(w, 3);printf("power(-0.1,3) = %lf\n", p); w = 0.1; p = power(w, 3);printf("power(0.1,3) = %lf\n", p); #include func1.c Lecture 15 - Prof. Paul I. Lin 40 20

21 Example 9-8: Testing Functions (cont.) /* func1.c - A file consists of functions */ int min(int a, int b) int z; if(a < b) z = a; else z = b; return z; int max(int a, int b) int x; x = (a > b)? a: b; return x; double power(float x, int n) double y = 1.0; if(n == 0) return 1.0; if(n < 0) x = 1.0/x; n = -n; while(n-- > 0) y *= x; return y; Lecture 15 - Prof. Paul I. Lin 41 Example 9-8: Testing Function (cont.) Output: min = 10 max = 20 power(0.0,3) = power(-0.1,3) = power(0.1,3) = Lecture 15 - Prof. Paul I. Lin 42 21

22 Summary C Functions Function Prototypes Function Definitions Function Calls by Value and by Reference 8 Example Programs Next Standard Mathematics Functions <math.h> More examples using <math.h> Standard Utility Functions <stdlib.h> Lecture 15 - Prof. Paul I. Lin 43 Question? Answers lin@ipfw.edu Lecture 15 - Prof. Paul I. Lin 44 22

C Programming for Engineers Functions

C Programming for Engineers Functions C Programming for Engineers Functions ICEN 360 Spring 2017 Prof. Dola Saha 1 Introduction Real world problems are larger, more complex Top down approach Modularize divide and control Easier to track smaller

More information

BSM540 Basics of C Language

BSM540 Basics of C Language BSM540 Basics of C Language Chapter 9: Functions I Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture Introduce the switch and goto statements Introduce the arrays in C

More information

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU CSE101-lec#12 Designing Structured Programs Introduction to Functions Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Designing structured programs in C: Counter-controlled repetition

More information

Functions. Arash Rafiey. September 26, 2017

Functions. Arash Rafiey. September 26, 2017 September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic

More information

Functions. Systems Programming Concepts

Functions. Systems Programming Concepts Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value

More information

Chapter 7 Functions. Now consider a more advanced example:

Chapter 7 Functions. Now consider a more advanced example: Chapter 7 Functions 7.1 Chapter Overview Functions are logical groupings of code, a series of steps, that are given a name. Functions are especially useful when these series of steps will need to be done

More information

Programming for Engineers Functions

Programming for Engineers Functions Programming for Engineers Functions ICEN 200 Spring 2018 Prof. Dola Saha 1 Introduction Real world problems are larger, more complex Top down approach Modularize divide and control Easier to track smaller

More information

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

Technical Questions. Q 1) What are the key features in C programming language?

Technical Questions. Q 1) What are the key features in C programming language? Technical Questions Q 1) What are the key features in C programming language? Portability Platform independent language. Modularity Possibility to break down large programs into small modules. Flexibility

More information

ECET 264 C Programming Language with Applications. C Program Control

ECET 264 C Programming Language with Applications. C Program Control ECET 264 C Programming Language with Applications Lecture 7 C Program Control Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 7 - Paul I. Lin

More information

Lecture 04 FUNCTIONS AND ARRAYS

Lecture 04 FUNCTIONS AND ARRAYS Lecture 04 FUNCTIONS AND ARRAYS 1 Motivations Divide hug tasks to blocks: divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions

More information

Lecture 16. Daily Puzzle. Functions II they re back and they re not happy. If it is raining at midnight - will we have sunny weather in 72 hours?

Lecture 16. Daily Puzzle. Functions II they re back and they re not happy. If it is raining at midnight - will we have sunny weather in 72 hours? Lecture 16 Functions II they re back and they re not happy Daily Puzzle If it is raining at midnight - will we have sunny weather in 72 hours? function prototypes For the sake of logical clarity, the main()

More information

Language comparison. C has pointers. Java has references. C++ has pointers and references

Language comparison. C has pointers. Java has references. C++ has pointers and references Pointers CSE 2451 Language comparison C has pointers Java has references C++ has pointers and references Pointers Values of variables are stored in memory, at a particular location A location is identified

More information

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful

More information

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:

More information

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved. Functions In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. You can either use the built-in library functions or you can create

More information

Introduction to Programming (Java) 4/12

Introduction to Programming (Java) 4/12 Introduction to Programming (Java) 4/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction

More information

Unit 7. Functions. Need of User Defined Functions

Unit 7. Functions. Need of User Defined Functions Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have

More information

CSE 2421: Systems I Low-Level Programming and Computer Organization. Functions. Presentation C. Predefined Functions

CSE 2421: Systems I Low-Level Programming and Computer Organization. Functions. Presentation C. Predefined Functions CSE 2421: Systems I Low-Level Programming and Computer Organization Functions Read/Study: Reek Chapters 7 Gojko Babić 01-22-2018 Predefined Functions C comes with libraries of predefined functions E.g.:

More information

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 1 Functions Functions are everywhere in C Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Introduction Function A self-contained program segment that carries

More information

Chapter 4 Functions By C.K. Liang

Chapter 4 Functions By C.K. Liang 1 Chapter 4 Functions By C.K. Liang What you should learn? 2 To construct programs modularly from small pieces called functions Math functions in C standard library Create new functions Pass information

More information

Lecture 04 FUNCTIONS AND ARRAYS

Lecture 04 FUNCTIONS AND ARRAYS Lecture 04 FUNCTIONS AND ARRAYS 1 Motivations Divide hug tasks to blocks: divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions

More information

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction Functions Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur Programming and Data Structure 1 Function Introduction A self-contained program segment that

More information

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura CS 2060 Week 4 1 Modularizing Programs Modularizing programs in C Writing custom functions Header files 2 Function Call Stack The function call stack Stack frames 3 Pass-by-value Pass-by-value and pass-by-reference

More information

CSCI 2132 Software Development. Lecture 17: Functions and Recursion

CSCI 2132 Software Development. Lecture 17: Functions and Recursion CSCI 2132 Software Development Lecture 17: Functions and Recursion Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 15-Oct-2018 (17) CSCI 2132 1 Previous Lecture Example: binary

More information

User Defined Functions

User Defined Functions User Defined Functions CS 141 Lecture 4 Chapter 5 By Ziad Kobti 27/01/2003 (c) 2003 by Ziad Kobti 1 Outline Functions in C: Definition Function Prototype (signature) Function Definition (body/implementation)

More information

Personal SE. Functions, Arrays, Strings & Command Line Arguments

Personal SE. Functions, Arrays, Strings & Command Line Arguments Personal SE Functions, Arrays, Strings & Command Line Arguments Functions in C Syntax like Java methods but w/o public, abstract, etc. As in Java, all arguments (well, most arguments) are passed by value.

More information

A PROBLEM can be solved easily if it is decomposed into parts. Similarly a C program decomposes a program into its component functions.

A PROBLEM can be solved easily if it is decomposed into parts. Similarly a C program decomposes a program into its component functions. FUNCTIONS IN C A PROBLEM can be solved easily if it is decomposed into parts. Similarly a C program decomposes a program into its component functions. Big problems require big programs too big to be written

More information

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer. Functions A number of statements grouped into a single logical unit are called a function. The use of function makes programming easier since repeated statements can be grouped into functions. Splitting

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 5: Functions. Scope of variables. Program structure. Cristina Nita-Rotaru Lecture 5/ Fall 2013 1 Functions: Explicit declaration Declaration, definition, use, order matters.

More information

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation. Lab 4 Functions Introduction: A function : is a collection of statements that are grouped together to perform an operation. The following is its format: type name ( parameter1, parameter2,...) { statements

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

UNIT III (PART-II) & UNIT IV(PART-I)

UNIT III (PART-II) & UNIT IV(PART-I) UNIT III (PART-II) & UNIT IV(PART-I) Function: it is defined as self contained block of code to perform a task. Functions can be categorized to system-defined functions and user-defined functions. System

More information

Procedural programming with C

Procedural programming with C Procedural programming with C Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 77 Functions Similarly to its mathematical

More information

Arrays and Pointers. CSE 2031 Fall November 11, 2013

Arrays and Pointers. CSE 2031 Fall November 11, 2013 Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example

More information

CS1150 Principles of Computer Science Methods

CS1150 Principles of Computer Science Methods CS1150 Principles of Computer Science Methods Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Opening Problem Find the sum of integers from 1 to

More information

MODULE 3: Arrays, Functions and Strings

MODULE 3: Arrays, Functions and Strings MODULE 3: Arrays, Functions and Strings Contents covered in this module I. Using an Array II. Functions in C III. Argument Passing IV. Functions and Program Structure, locations of functions V. Function

More information

Parameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265

Parameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265 Parameter passing Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria 1 SEng 265 dmgerman@uvic.ca C implements call-by-value parameter passing int a =

More information

Fundamentals of Programming & Procedural Programming

Fundamentals of Programming & Procedural Programming Universität Duisburg-Essen PRACTICAL TRAINING TO THE LECTURE Fundamentals of Programming & Procedural Programming Session Four: Functions: Built-in, Parameters and Arguments, Fruitful and Void Functions

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science Department Lecture 3: C# language basics Lecture Contents 2 C# basics Conditions Loops Methods Arrays Dr. Amal Khalifa, Spr 2015 3 Conditions and

More information

BSM540 Basics of C Language

BSM540 Basics of C Language BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()

More information

/* EXAMPLE 1 */ #include<stdio.h> int main() { float i=10, *j; void *k; k=&i; j=k; printf("%f\n", *j);

/* EXAMPLE 1 */ #include<stdio.h> int main() { float i=10, *j; void *k; k=&i; j=k; printf(%f\n, *j); You try /* EXAMPLE 3 */ #include int main(void) { char ch = 'c'; char *chptr = &ch; int i = 20; int *intptr = &i; float f = 1.20000; float *fptr = &f; char *ptr = "I am a string"; /* EXAMPLE

More information

Functions BCA-105. Few Facts About Functions:

Functions BCA-105. Few Facts About Functions: Functions When programs become too large and complex and as a result the task of debugging, testing, and maintaining becomes difficult then C provides a most striking feature known as user defined function

More information

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014. Arrays Arrays and Pointers l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. EECS 2031 Fall 2014 November 11, 2013 1 2 Arrays: Example

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 5: Functions. Scope. 1 Functions: Explicit declaration Declaration, definition, use, order matters. Declaration: defines the interface of a function; i.e., number and types

More information

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2013 C++ Programming Language Lab # 6 Functions C++ Programming Language Lab # 6 Functions Objective: To be familiar with

More information

Functions Introduction to Algorithms and Programming II School of Computer Science Term: Summer 2013 Instructor: Dr. Asish Mukhopadhyay

Functions Introduction to Algorithms and Programming II School of Computer Science Term: Summer 2013 Instructor: Dr. Asish Mukhopadhyay Functions 60-141 Introduction to Algorithms and Programming II School of Computer Science Term: Summer 2013 Instructor: Dr. Asish Mukhopadhyay Motivation A complex program Approximate Ellipse Demo Ellipse2DDouble.java

More information

CSCI 2132 Software Development. Lecture 18: Functions

CSCI 2132 Software Development. Lecture 18: Functions CSCI 2132 Software Development Lecture 18: Functions Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 18-Oct-2017 (18) CSCI 2132 1 Previous Lecture Example: binary search Multidimensional

More information

ECET 264 C Programming Language with Applications

ECET 264 C Programming Language with Applications ECET 264 C Programming Language with Applications Lecture 10 C Standard Library Functions Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 10

More information

Arrays and Pointers (part 1)

Arrays and Pointers (part 1) Arrays and Pointers (part 1) CSE 2031 Fall 2012 Arrays Grouping of data of the same type. Loops commonly used for manipulation. Programmers set array sizes explicitly. Arrays: Example Syntax type name[size];

More information

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single Functions in C++ Problem-Solving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module

More information

AMCAT Automata Coding Sample Questions And Answers

AMCAT Automata Coding Sample Questions And Answers 1) Find the syntax error in the below code without modifying the logic. #include int main() float x = 1.1; switch (x) case 1: printf( Choice is 1 ); default: printf( Invalid choice ); return

More information

CS113: Lecture 4. Topics: Functions. Function Activation Records

CS113: Lecture 4. Topics: Functions. Function Activation Records CS113: Lecture 4 Topics: Functions Function Activation Records 1 Why functions? Functions add no expressive power to the C language in a formal sense. Why have them? Breaking tasks into smaller ones make

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 PROGRAMMAZIONE I A.A. 2017/2018 FUNCTIONS INTRODUCTION AND MAIN All the instructions of a C program are contained in functions. üc is a procedural language üeach function performs a certain task A special

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 4 FUNCTIONS. 4.1 Introduction CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main

More information

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa Functions Autumn Semester 2009 Programming and Data Structure 1 Courtsey: University of Pittsburgh-CSD-Khalifa Introduction Function A self-contained program segment that carries out some specific, well-defined

More information

Unit 3 Functions. 1 What is user defined function? Explain with example. Define the syntax of function in C.

Unit 3 Functions. 1 What is user defined function? Explain with example. Define the syntax of function in C. 1 What is user defined function? Explain with example. Define the syntax of function in C. A function is a block of code that performs a specific task. The functions which are created by programmer are

More information

Chapter 5 C Functions

Chapter 5 C Functions Chapter 5 C Functions Objectives of this chapter: To construct programs from small pieces called functions. Common math functions in math.h the C Standard Library. sin( ), cos( ), tan( ), atan( ), sqrt(

More information

Computer Programming

Computer Programming Computer Programming Introduction Marius Minea marius@cs.upt.ro http://cs.upt.ro/ marius/curs/cp/ 26 September 2017 Course goals Learn programming fundamentals no prior knowledge needed for those who know,

More information

Lab 3. Pointers Programming Lab (Using C) XU Silei

Lab 3. Pointers Programming Lab (Using C) XU Silei Lab 3. Pointers Programming Lab (Using C) XU Silei slxu@cse.cuhk.edu.hk Outline What is Pointer Memory Address & Pointers How to use Pointers Pointers Assignments Call-by-Value & Call-by-Address Functions

More information

Opening Problem. Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.

Opening Problem. Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. Chapter 6 Methods 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 A Solution int sum = 0; for (int i = 1; i

More information

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga C-Programming CSC209: Software Tools and Systems Programming Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Adapted from Dan Zingaro s 2015 slides. Week 2.0 1 / 19 What

More information

M.CS201 Programming language

M.CS201 Programming language Power Engineering School M.CS201 Programming language Lecture 16 Lecturer: Prof. Dr. T.Uranchimeg Agenda Opening a File Errors with open files Writing and Reading File Data Formatted File Input Direct

More information

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016 Chapter 6: User-Defined Functions Objectives In this chapter, you will: Learn about standard (predefined) functions Learn about user-defined functions Examine value-returning functions Construct and use

More information

Engineering program development 6. Edited by Péter Vass

Engineering program development 6. Edited by Péter Vass Engineering program development 6 Edited by Péter Vass Variables When we define a variable with its identifier (name) and type in the source code, it will result the reservation of some memory space for

More information

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock) C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 By the end of this lecture, you will be able to identify the

More information

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 1 By the end of this lecture, you will be able to identify

More information

Chapter 8: Function. In this chapter, you will learn about

Chapter 8: Function. In this chapter, you will learn about Principles of Programming Chapter 8: Function In this chapter, you will learn about Introduction to function User-defined function Formal and Actual Parameters Parameter passing by value Parameter passing

More information

EECS402 Lecture 02. Functions. Function Prototype

EECS402 Lecture 02. Functions. Function Prototype The University Of Michigan Lecture 02 Andrew M. Morgan Savitch Ch. 3-4 Functions Value and Reference Parameters Andrew M. Morgan 1 Functions Allows for modular programming Write the function once, call

More information

M.CS201 Programming language

M.CS201 Programming language Power Engineering School M.CS201 Programming language Lecture 14 Lecturer: Prof. Dr. T.Uranchimeg Agenda Ending Loops Early The break Statement The continue Statement Executing Operating System Commands

More information

Lecture 2: C Programming Basic

Lecture 2: C Programming Basic ECE342 Introduction to Embedded Systems Lecture 2: C Programming Basic Ying Tang Electrical and Computer Engineering Rowan University 1 Facts about C C was developed in 1972 in order to write the UNIX

More information

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function

More information

Programming. Functions and File I/O

Programming. Functions and File I/O Programming Functions and File I/O Summary Functions Definition Declaration Invocation Pass by value vs. pass by reference File I/O Reading Writing Static keyword Global vs. local variables 2 Functions

More information

EC 413 Computer Organization

EC 413 Computer Organization EC 413 Computer Organization C/C++ Language Review Prof. Michel A. Kinsy Programming Languages There are many programming languages available: Pascal, C, C++, Java, Ada, Perl and Python All of these languages

More information

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012 CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012 TOPICS TODAY Assembling & Linking Assembly Language Separate Compilation in C Scope and Lifetime LINKING IN ASSEMBLY

More information

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly

More information

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 10: Arrays Readings: Chapter 9 Introduction Group of same type of variables that have same

More information

CS1150 Principles of Computer Science Methods

CS1150 Principles of Computer Science Methods CS1150 Principles of Computer Science Methods Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Opening Problem Find the sum of integers from 1 to

More information

C Programming Language

C Programming Language C Programming Language Arrays & Pointers I Dr. Manar Mohaisen Office: F208 Email: manar.subhi@kut.ac.kr Department of EECE Review of Precedent Class Explain How to Create Simple Functions Department of

More information

Lecture 4: Outline. Arrays. I. Pointers II. III. Pointer arithmetic IV. Strings

Lecture 4: Outline. Arrays. I. Pointers II. III. Pointer arithmetic IV. Strings Lecture 4: Outline I. Pointers A. Accessing data objects using pointers B. Type casting with pointers C. Difference with Java references D. Pointer pitfalls E. Use case II. Arrays A. Representation in

More information

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont)

Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont) CP Lect 5 slide 1 Monday 2 October 2017 Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont) Cristina Alexandru Monday 2 October 2017 Last Lecture Arithmetic Quadratic equation

More information

Lecture 5: Methods CS2301

Lecture 5: Methods CS2301 Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

More information

Fundamentals of Computer Programming Using C

Fundamentals of Computer Programming Using C CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US01CBCA01 (Fundamentals of Computer Programming Using C) *UNIT 3 (Structured Programming, Library Functions

More information

Opening Problem. Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.

Opening Problem. Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. Chapter 6 Methods 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 A Solution int sum = 0; for (int i = 1; i

More information

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017 Pointers (part 1) EECS 2031 25 September 2017 1 What are pointers? We have seen pointers before. scanf( %f, &inches );! 2 1 Example char c; c = getchar(); printf( %c, c); char c; char *p; c = getchar();

More information

Arrays and Pointers (part 1)

Arrays and Pointers (part 1) Arrays and Pointers (part 1) CSE 2031 Fall 2010 17 October 2010 1 Arrays Grouping of data of the same type. Loops commonly used for manipulation. Programmers set array sizes explicitly. 2 1 Arrays: Example

More information

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am Announcements PS 3 is due Thursday, 10/6 Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am Room TBD Scope: Lecture 1 to Lecture 9 (Chapters 1 to 6 of text) You may bring a sheet of paper (A4, both sides) Tutoring

More information

Binding and Variables

Binding and Variables Binding and Variables 1. DEFINITIONS... 2 2. VARIABLES... 3 3. TYPE... 4 4. SCOPE... 4 5. REFERENCES... 7 6. ROUTINES... 9 7. ALIASING AND OVERLOADING... 10 8. GENERICS AND TEMPLATES... 12 A. Bellaachia

More information

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions Lecture 02 Summary C/Java Syntax Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 1 2 By the end of this lecture, you will be able to identify the

More information

Programming and Data Structures

Programming and Data Structures Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()

More information

CS101 Introduction to computing Function, Scope Rules and Storage class

CS101 Introduction to computing Function, Scope Rules and Storage class CS101 Introduction to computing Function, Scope Rules and Storage class A. Sahu and S. V.Rao Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati Outline Functions Modular d l Program Inbuilt

More information

Computers in Engineering. Moving From Fortran to C Part 2 Michael A. Hawker

Computers in Engineering. Moving From Fortran to C Part 2 Michael A. Hawker Computers in Engineering COMP 208 Moving From Fortran to C Part 2 Michael A. Hawker Roots of a Quadratic in C #include #include void main() { float a, b, c; float d; float root1, root2;

More information

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers Computer Science & Engineering 150A Problem Solving Using Computers Lecture 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A

More information

ECET 264 C Programming Language with Applications

ECET 264 C Programming Language with Applications ECET 264 C Programming Language with Applications Lecture 6 Control Structures and More Operators Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture

More information

& Technology. G) Functions. void. Argument2, Example: (Argument1, Syllabus for 1. 1 What. has a unique. 2) Function name. passed to.

& Technology. G) Functions. void. Argument2, Example: (Argument1, Syllabus for 1. 1 What. has a unique. 2) Function name. passed to. Computer Programming and Utilization (CPU) 110003 G) Functions 1 What is user defined function? Explain with example. Define the syntax of function in C. A function is a block of code that performs a specific

More information

Computers in Engineering COMP 208. Roots of a Quadratic in C 10/25/2007. Moving From Fortran to C Part 2 Michael A. Hawker

Computers in Engineering COMP 208. Roots of a Quadratic in C 10/25/2007. Moving From Fortran to C Part 2 Michael A. Hawker Computers in Engineering COMP 208 Moving From Fortran to C Part 2 Michael A. Hawker Roots of a Quadratic in C #include #include void main() { float a, b, c; floatd; float root1, root2;

More information

Engineering program development 7. Edited by Péter Vass

Engineering program development 7. Edited by Péter Vass Engineering program development 7 Edited by Péter Vass Functions Function is a separate computational unit which has its own name (identifier). The objective of a function is solving a well-defined problem.

More information

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ FUNCTIONS Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Functions: Program modules in C Function Definitions Function

More information