Lecture6_handout

Lecture6_handout - Overview EE140: Introduction to to...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 EE140: Introduction to 0t o d u c t o t o Programming Concepts for Engineers Lecture 6 1 Functions Overview Define and call a function Function prototype Scope of a variable 2 Define a function A simple C function is a named block of statements ach function is used to solve a problem Each function is used to solve a problem return_type name (type1 var1, type2 var2, . ..) { Function name The type of value returned by the function. If no value will be returned by the function, we use void as the return type. Input parameters, each must have a data type. Use () or (void) if no parameter This line is the function header 3 variable declarations; statements; return value; } ouble area (double radius) Define a function to calculate the area of a circle nction name: rea Define and call a function double area (double radius) { double a; a=PI*radius*radius; return a; } function name: area function input: double radius function output: double Call a function x=area (i); 4 statement calls or invokes the function area() value of ‘i’ is passed to area() and copied to the parameter ‘radius’. You can use same name if you want. the value returned by area() is assigned back to ‘x’ ();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Example 1 Write a program to calculate the area of a circle using a function #include<stdio.h> double area( double radius ) { return (3.14159 * radius * radius); } int main( void ) { double i=2.5, radius, circle_area ; printf( "Enter the Circle Radius : ") ;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Lecture6_handout - Overview EE140: Introduction to to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online