What are functions? 1. A piece of code that performs an operation that can be used by the main program or by other functions 2. A sophisticated if –else.

Slides:



Advertisements
Similar presentations
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 10 – Enhancing the Wage Calculator Application:
Advertisements

1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
8 – 6 The Sine and Cosine Ratios. Sine and Cosine Suppose you want to fine the legs, x and y, in a triangle. You can’t find these values using the tangent.
Lecture 10: Don't Reinvent the Wheel. Exam Results.
1 ICS103 Programming in C Lecture 5: Introduction to Functions.
CS 201 Functions Debzani Deb.
Chapter 6: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
Top-Down Design with Functions 4 What do programmer’s (not programs!) use as input to the design of a program? –Documentation Problem definition Requirements.
PHYS 2020 Basic C An introduction to writing simple but useful programs in C In these lectures I will take you through the basics of C, but you will need.
Chapter 6: User-Defined Functions I
Starter a 6 c A 53° 84° 1.Use Law of Sines to calculate side c of the triangle. 2.Use the Law of Cosines to calculate side a of the triangle. 3.Now find.
12-2 Know how if and switch C statements control the sequence of execution of statements. Be able to use relational and logical operators in the conditional.
Introduction to C. A Brief History Created by Dennis Ritchie at AT&T Labs in 1972 Originally created to design and support the Unix operating system.
CSCI 130 Chapter 2. Program Components main() #include Variable Definition Function Prototype Program Statements Function Call Function Definition Comments.
Algebra 2 Section 2: Properties of Real Numbers
Sine, Cosine and Tangent Ratios Objective Students will be able to use sine, cosine, and tangent ratios to determine side lengths in triangles.
CS61A Lecture 2 Functions and Applicative Model of Computation Tom Magrino and Jon Kotker UC Berkeley EECS June 19, 2012.
Trigonometry Unit 2: 2-dimensional Motion From:
Functions Lecture 4 – Section 2: 9/21/05 Section 4: 9/22/05.
Agenda Review Compiling Review Data Types Integer Division Composition C++ Mathematical Functions User Input Reading: , 8.11 Homework #3.
Computational physics PY2050 Course Details:
Trigonometry. Basic Ratios Find the missing Law of Sines Law of Cosines Special right triangles
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
16&17-2 Grasp the concept of top-down programming Identify Function Headers and Prototypes Understand when and where prototypes used Understand how arguments.
Lecture 2: Static Methods, if statements, homework uploader.
Table of Contents 5. Right Triangle Trigonometry
Chapter 06 (Part I) Functions and an Introduction to Recursion.
1 Lecture04: Function Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
Week 2 - Friday.  What did we talk about last time?  Base systems  C literals  Representations in memory.
1 ICS103 Programming in C Lecture 7: Introduction to Functions.
USER-DEFINED FUNCTIONS. STANDARD (PREDEFINED) FUNCTIONS  In college algebra a function is defined as a rule or correspondence between values called the.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 6 User-Defined Functions I. Objectives Standard (predefined) functions What are they, and How to use them User-Defined Functions Value returning.
GEOMETRY HELP Use the triangle to find sin T, cos T, sin G, and cos G. Write your answer in simplest terms. sin T = = = opposite hypotenuse.
CC112 Structured Programming Lecture 2 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Math Library Functions
CSCI 125 & 161 / ENGR 144 Lecture 8 Martin van Bommel.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter : Trigonometry Lesson 3: Finding the Angles.
8.3 Trigonometry. Similar right triangles have equivalent ratios for their corresponding sides. These equivalent ratios are called Trigonometric Ratios.
CSC1201: Programming Language 2 1 Functions. 2 Function declaration: return_type FuncName( Type arg1, Type arg2,….. Type argN) { function body } A program.
Introduction to Programming Lecture 6. Functions – Call by value – Call by reference Today's Lecture Includes.
7.5 and 7.6 Trigonometric Ratios The Legend of SOH CAH TOA...Part 1 The Legend of SOH CAH TOA...Part 1.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Lesson 8-6 The Sine and Cosine Ratios (page 312) The sine ratio and cosine ratio relate the legs to the hypotenuse. How can trigonometric ratios be used.
Event 1 Principles of Programming Hugh Davis ECS The University of Southampton, UK users.ecs.soton.ac.uk/hcd.
UMBC CMSC 104 – Section 01, Fall 2016
1.3 ARITHMETIC OPERATIONS WITH SCALARS
Programming Fundamentals Lecture #7 Functions
CSC113: Computer Programming (Theory = 03, Lab = 01)
FUNCTIONS.
Functions.
Functions Declarations CSCI 230
CSC1201: Programming Language 2
Programming Fundamentals Lecture #3 Overview of Computer Programming
2.4 cosine law Let’s take a look at various trigonometric curves before moving on Understanding how the curves look for sine, cosine, tangent and their.
Homework K&R chapter 4.
Calculate 81 ÷ 3 = 27 3 x 3 x 3 3 x 3 x 3 x 3 ÷ 3 = This could be written as
Computational physics: intro workshop
Week 2 - Friday CS222.
Presentation transcript:

What are functions? 1. A piece of code that performs an operation that can be used by the main program or by other functions 2. A sophisticated if –else statement that always goes into the else part and never into the if part 3.Just some stuff the compiler uses and the user never has to use or see 4. An out of this world thrill ride at the Walt Disney World Resort in Orlando, FL!!!

Using Functions Avoid re-inventing the wheel Using existing functions as building-blocks to create new programs “Prepackaged” functions in the C Standard Library can be used. User-defined functions can also be used (talk about this next lecture).

Example: Suppose you want to find cos(90°). 90° = π/2 One way would be to calculate the power series: Or, you can just use include the math.h header which contains a built in cosine function.

Commonly Used Math Library Functions

For your in class assignment Use #include math.h Take a look at /usr/include/math.h and note the #define Use M_PI for pi or define your own pi. Use the function acos(argument) to find the inverse cosine In order to compile using the math library, you must use a compiler flag –lm: gcc program.c –lm –o executable Or gcc program.c –o executable –lm (this way is better)

Law of Cosines Leg 2 Leg 1 Hypotenuse