8-Functions - Functions: - using Library functions -...

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

View Full Document Right Arrow Icon
Functions: - using Library functions - writing our own
Background image of page 1

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

View Full DocumentRight Arrow Icon
#include <cmath> a math library x = pow( 12, 2 ); " function "
Background image of page 2
functions a math library x = pow( 12, 2 ); that's what parenthesis are for!! sent TO a function returned FROM a function
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
Step 1 - think of a good name addTwoNumbers( )
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
return as a service? int
Background image of page 8
Image of page 9
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.

Page1 / 13

8-Functions - Functions: - using Library functions -...

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

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