Computer Science: A Structured Programming Approach Using C1 4-5 Standard Functions C provides a rich collection of standard functions whose definitions.

Slides:



Advertisements
Similar presentations
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
Advertisements

Methods Java 5.1 A quick overview of methods
Chapter Five Functions
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Functions. COMP104 Functions / Slide 2 Introduction to Functions * A complex problem is often easier to solve by dividing it into several smaller parts,
Return values.
Excel Part I Basics and Simple Plotting Section 008 Fall 2013 EGR 105 Foundations of Engineering I.
Arithmetic in Pascal (2) Arithmetic Functions Perform arithmetic calculations Gives an argument to the function and it returns the result.
Maths & Trig, Statistical functions. ABS Returns the absolute value of a number The absolute value of a number is the number without its sign Syntax ◦
Computer Science: A Structured Programming Approach Using C1 8-4 Array Applications In this section we study two array applications: frequency arrays with.
 Monday, 10/28/02, Slide #1 CS106 Introduction to CS1 Monday, 10/28/02  QUESTIONS on HW 03??  Today: Generating random numbers  Reading & exercises:
CSE 341 Lecture 19 parsing / Homework 7 slides created by Marty Stepp
1 Session-23 CSIT 121 Spring 2006 Revision Ch 7: Reference Parameters Revision Ch 7: Reference Parameters Chapter 8: Value Returning Functions Chapter.
 2007 Pearson Education, Inc. All rights reserved C Functions.
 2007 Pearson Education, Inc. All rights reserved C Functions.
1 Lab Session-9 CSIT-121 Fall 2003 w Random Number Generation w Designing a Game.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
EGR 105 Foundations of Engineering I Session 3 Excel – Basics through Graphing Fall 2008.
 2000 Prentice Hall, Inc. All rights reserved. Functions in C Outline 1Introduction 2Program Modules in C 3Math Library Functions 4Functions 5Function.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) MATH Functions in C Language.
Functions in C Outline 1Introduction 2Program Modules in C 3Math Library Functions 4Functions 5Function Definitions 6Function Prototypes 7Header Files.
Chapter 3 Expressions and Interactivity Department of Computer Science Missouri State Univeristy.
MATH AND RANDOM CLASSES.  The need for random numbers occurs frequently when writing software.  The Random class, which is part of the java.util class,
Iterative Constructs Review l What are named constants? Why are they needed? l What is a block? What is special about declaring a variable inside a block?
1 Math Expressions and Operators. 2 Some C++ Operators Precedence OperatorDescription Higher ( )Function call +Positive - Negative *Multiplication / Division.
1 Week 2: Variables and Assignment Statements READING: 1.4 – 1.6 EECS Introduction to Computing for the Physical Sciences.
CMSC 1041 Functions II Functions that return a value.
Today’s Lecture Predefined Functions. Introduction to Functions  Reuse Issue  Building Blocks of Programs  Two types of functions  Predefined  Programmer.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
 2008 Pearson Education, Inc. All rights reserved Case Study: Random Number Generation C++ Standard Library function rand – Introduces the element.
Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with.
Computer Science: A Structured Programming Approach Using C Graphs A graph is a collection of nodes, called vertices, and a collection of segments,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
CS 261 – Recitation 2 Fall 2013 Oregon State University School of Electrical Engineering and Computer Science.
CSCE 121: Introduction to Program Design and Concepts, Honors J. Michael Moore Spring 2015 Set 14: Plotting Functions and Data 1.
Cpt S 223 – Advanced Data Structures Math Review 2
Basics and arrays Operators:  Arithmetic: +, -, *, /, %  Relational:, >=, ==, !=  Logical: &&, ||, ! Primitive data types Byte(8), short(16), int(32),
1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.
PHY 107 – Programming For Science. Announcements  Lectures may not cover all material from readings  Material that is most difficult or challenging.
SubPrograms Top-Down Design using stepwise refinement leads to division of tasks.
Random numbers in C++ Nobody knows what’s next....
+ Arrays & Random number generator. + Introduction In addition to arrays and structures, C supports creation and manipulation of the following data structures:
1D Arrays and Random Numbers Artem A. Lenskiy, PhD May 26, 2014.
Creating and Using Class Methods. Definition Class Object.
ONE DIMENSIONAL ARRAYS AND RANDOM NUMBERS. Introduction In addition to arrays and structures, C supports creation and manipulation of the following data.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
1 Generating Random Numbers Textbook ch.6, pg
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
L131 Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips rand( ) math library functions Reading Sections.
CSE 110: Programming Language I Afroza Sultana UB 1230.
Mathematical Functions
Functions, Part 2 of 2 Topics Functions That Return a Value
Iterative Constructs Review
C Short Overview Lembit Jürimägi.
CSC113: Computer Programming (Theory = 03, Lab = 01)
Deitel- C:How to Program (5ed)
Lab Session-9 CSIT-121 Spring 2005
Topics discussed in this section:
Functions October 23, 2017.
Iterative Constructs Review
Topics discussed in this section:
Topics discussed in this section:
Topics discussed in this section:
Php – Math functions.
Introduction to C++ Programming Language
Topics discussed in this section:
Module 14 Miscellaneous Topics
Presentation transcript:

Computer Science: A Structured Programming Approach Using C1 4-5 Standard Functions C provides a rich collection of standard functions whose definitions have been written and are ready to be used in our programs. To use these functions, we must include their function declarations. Math Functions Random Numbers Topics discussed in this section:

Computer Science: A Structured Programming Approach Using C2 FIGURE 4-26 Library Functions and the Linker

Some functions #include abs() int = abs(int) rand() srand() Others: malloc, qsort, etc. Computer Science: A Structured Programming Approach Using C3

Math functions #include trig: cos(), etc. pow(base, exp); log, exp, etc. sqrt() ceil(), floor(), trunc(), round(), etc. Computer Science: A Structured Programming Approach Using C4

5 FIGURE 4-27 Ceiling Function

Computer Science: A Structured Programming Approach Using C6 FIGURE 4-28 Floor Function

Computer Science: A Structured Programming Approach Using C7 FIGURE 4-29 Random Number Generation

Computer Science: A Structured Programming Approach Using C8 FIGURE 4-30 Generating a Random Number Series

Computer Science: A Structured Programming Approach Using C9 srand must be called only once for each random number series. Note

Computer Science: A Structured Programming Approach Using C10 PROGRAM 4-9Creating Temporal Random Numbers

Computer Science: A Structured Programming Approach Using C11 PROGRAM 4-9Creating Temporal Random Numbers

Computer Science: A Structured Programming Approach Using C12 PROGRAM 4-10Creating Pseudorandom Numbers

Computer Science: A Structured Programming Approach Using C13 PROGRAM 4-10Creating Pseudorandom Numbers

Computer Science: A Structured Programming Approach Using C14 FIGURE 4-31 Random Number Scaling for 3–7

Computer Science: A Structured Programming Approach Using C15 PROGRAM 4-11Generating Random Numbers in the Range 10 to 20

Computer Science: A Structured Programming Approach Using C16 PROGRAM 4-11Generating Random Numbers in the Range 10 to 20

Computer Science: A Structured Programming Approach Using C17 PROGRAM 4-12Generating Random Real Numbers

Computer Science: A Structured Programming Approach Using C18 PROGRAM 4-12Generating Random Real Numbers