This preview shows pages 1–9. Sign up to view the full content.
Functions:
 using Library functions
 writing our own
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document #include <cmath>
a math library
x
= pow( 12, 2 );
" function "
functions
a math library
x
= pow( 12, 2 );
that's what parenthesis are for!!
sent TO a function
returned FROM a function
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document cmath functions
Function
Description
abs(x)
computes absolute value of x
sqrt(x)
computes square root of x, where x >=0
pow(x,y)
computes x
y
ceil(x)
nearest integer larger than x
floor(x)
nearest integer smaller than x
exp(x)
computes e
x
log(x)
computes ln x, where x >0
log10(x)
computes log
10
x, where x>0
sin(x)
sine of x, where x is in radians
cos(x)
cosine of x, where x is in radians
tan(x)
tangent of x, where x is in radians
note the value passed
TO
the function
writing our own
•
we can write functions right in our main
program
•
it involves 6 steps
•
why? to isolate code that you want to run
(“call”) repeatedly
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document Step 1  think of a good name
addTwoNumbers(
)
Step 2  decide what the function
needs to do its job
addTwoNumbers ( int addend1, int addend2)
you can name those variables anything you
want, but you have to specify their type
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
return as a service?
int
This is the end of the preview. Sign up
to
access the rest of the document.
This document was uploaded on 11/03/2011 for the course EAS 230 at SUNY Buffalo.
 Fall '09

Click to edit the document details