Chapter 5 Standard Features - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Chapter 5 Standard Features

Description:

Some Standard Functions in C . 3. Objectives ... hypot(a,b) Returns the hypotenuse of a right. triangle. log() Returns the natural log of the ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 16
Provided by: AndrewSt7
Category:

less

Transcript and Presenter's Notes

Title: Chapter 5 Standard Features


1
Chapter 5 Standard Features
CS240-Intermediate Programming
Created by Andrew StaugaardModified by Prof.
Martins
  • Chaminade University of Honolulu
  • Department of Computer Science

2
Contents
  • Arithmetic Operators
  • Assignment Operators
  • Some Standard Functions in C

3
Objectives
  • When you are finished with this chapter, you
    should have a good understanding of
  • The standard arithmetic operators in C
  • The order of precedence used for arithmetic
    operators in C
  • The standard mathematical functions provided by
    the math.h header files

4
Objectives
  • How to call the standard math functions
  • The increment/decrement operators
  • Pre-increment versus post-increment
  • Simple and compound assignment operators in c
  • The use of trig functions in C

5
Chapter 5
  • The C Arithmetic Operators
  • Addition
  • Subtraction
  • Multiplication ?
  • Division /
  • Modulus (remainder)
  • Increment
  • Decrement _ _

6
Order of Precedence
7
Increment/Decrement
  • If a variable is pre-incremented or
    pre-decremented within an expression, the
    variable is incremented/decremented before the
    expression is evaluated.
  • On the other hand, if a variable is post
    incremented or post decremented within an
    expression, the variable is incremented/decremente
    d after the expression is evaluated.

8
The C Assignment Operators
  • Simple assignment
  • Addition/assignment
  • Subtraction/assignment ?
  • Multiplication/assignment ?
  • Division/assignment /
  • Modulus/assignment

9
Conversion Functions
  • toascii() Converts a character to its
  • ASCII value.
  • tolower() Converts a character to
  • lowercase.
  • toupper() Converts a character to
  • uppercase.

10
Math Functions
  • abs() Returns the absolute value of the
  • argument.
  • acos() Returns the arc cos of the argument
  • (radians).
  • asin() Returns the arc sin of the argument
  • (radians).
  • atan() Returns the arc tan of the
  • argument (radians).
  • cos() Returns the cosine of the
    argument
  • (radians).

11
Math Functions
  • hypot(a,b) Returns the hypotenuse of a right
  • triangle.
  • log() Returns the natural log of the
  • argument.
  • log10() Returns the base 10 log of the
  • argument.

12
Math Functions (continued)
  • pow(x,y) Returns x raised to the power of
  • pow10(y) Returns 10 raised to the power of y.
  • rand() Generates random number.
  • srand() Initializes the random-number
  • generator .
  • sin() Returns the sine of the argument
  • (radians).

13
Math Functions (continued)
  • sqrt() Returns the square root of the
  • argument.
  • tan() Returns the tangent of the
  • argument (radians).

14
Chapter 5
  • Trig Functions Evaluate Radians, Not Degrees
  • The standard trig functions in the C math.h
    header file evaluate radians, not degrees.
    Multiply degrees by PI/180 within the trig
    function argument to convert degrees to radians.

15
Chapter 5
  • Generating A Random Number Between 0 and 99
  • srand(1) randomValue rand() 100
Write a Comment
User Comments (0)
About PowerShow.com