+ All Categories
Home > Documents > Computer Science: A Structured Programming Approach Using C1 4-5 Standard Functions C provides a...

Computer Science: A Structured Programming Approach Using C1 4-5 Standard Functions C provides a...

Date post: 21-Jan-2016
Category:
Upload: dinah-hood
View: 221 times
Download: 0 times
Share this document with a friend
Popular Tags:
18
Computer Science: A Structured Programming Approach Using C 1 -5 Standard Functions C provides a rich collection of standard C provides a rich collection of standard functions whose definitions have been written functions whose definitions have been written and are ready to be used in our programs. To and are ready to be used in our programs. To use these functions, we must include their use these functions, we must include their function declarations. function declarations. Math Functions Random Numbers Topics discussed in this section: Topics discussed in this section:
Transcript
Page 1: Computer Science: A Structured Programming Approach Using C1 4-5 Standard Functions C provides a rich collection of standard functions whose definitions.

Computer Science: A Structured Programming Approach Using C 1

4-5 Standard Functions

C provides a rich collection of standard functions C provides a rich collection of standard functions whose definitions have been written and are ready to whose definitions have been written and are ready to be used in our programs. To use these functions, we be used in our programs. To use these functions, we must include their function declarations.must include their function declarations.

Math FunctionsRandom Numbers

Topics discussed in this section:Topics discussed in this section:

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

Computer Science: A Structured Programming Approach Using C 2

FIGURE 4-26 Library Functions and the Linker

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

Some functions

#include<stdlib.h>

abs() int = abs(int)rand()srand()

Others: malloc, qsort, etc.Computer Science: A Structured Programming Approach Using C 3

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

Math functions

#include <math.h>trig: cos(), etc.pow(base, exp); log, exp, etc.sqrt()ceil(), floor(), trunc(), round(), etc.

Computer Science: A Structured Programming Approach Using C 4

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

Computer Science: A Structured Programming Approach Using C 5

FIGURE 4-27 Ceiling Function

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

Computer Science: A Structured Programming Approach Using C 6

FIGURE 4-28 Floor Function

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

Computer Science: A Structured Programming Approach Using C 7

FIGURE 4-29 Random Number Generation

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

Computer Science: A Structured Programming Approach Using C 8

FIGURE 4-30 Generating a Random Number Series

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

Computer Science: A Structured Programming Approach Using C 9

srand must be called only once for each randomnumber series.

NoteNote

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

Computer Science: A Structured Programming Approach Using C 10

PROGRAM 4-9 Creating Temporal Random Numbers

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

Computer Science: A Structured Programming Approach Using C 11

PROGRAM 4-9 Creating Temporal Random Numbers

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

Computer Science: A Structured Programming Approach Using C 12

PROGRAM 4-10 Creating Pseudorandom Numbers

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

Computer Science: A Structured Programming Approach Using C 13

PROGRAM 4-10 Creating Pseudorandom Numbers

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

Computer Science: A Structured Programming Approach Using C 14

FIGURE 4-31 Random Number Scaling for 3–7

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

Computer Science: A Structured Programming Approach Using C 15

PROGRAM 4-11 Generating Random Numbers in the Range 10 to 20

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

Computer Science: A Structured Programming Approach Using C 16

PROGRAM 4-11 Generating Random Numbers in the Range 10 to 20

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

Computer Science: A Structured Programming Approach Using C 17

PROGRAM 4-12 Generating Random Real Numbers

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

Computer Science: A Structured Programming Approach Using C 18

PROGRAM 4-12 Generating Random Real Numbers


Recommended