C Programming Language



Similar documents
Chapter 5 Functions. Introducing Functions

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

6.1 Basic Right Triangle Trigonometry

Trigonometric Functions and Triangles

ALGEBRA 2/TRIGONOMETRY

GRE Prep: Precalculus

Techniques of Integration

ALGEBRA 2/TRIGONOMETRY

Calculate the value of π

a cos x + b sin x = R cos(x α)

Final Exam Review: VBA

The OptQuest Engine Java and.net Developer's Guilde

Solutions to Homework 10

A very minimal introduction to TikZ

ab = c a If the coefficients a,b and c are real then either α and β are real or α and β are complex conjugates

Getting Started with MasteringPhysics

El Dorado Union High School District Educational Services

Math Placement Test Practice Problems

Triangle Trigonometry and Circles

Friday, January 29, :15 a.m. to 12:15 p.m., only

Chapter 8 Geometry We will discuss following concepts in this chapter.

Solutions to Exercises, Section 5.1

Simple C Programs. Goals for this Lecture. Help you learn about:

Algebra. Exponents. Absolute Value. Simplify each of the following as much as possible. 2x y x + y y. xxx 3. x x x xx x. 1. Evaluate 5 and 123

Getting Started with

Evaluating trigonometric functions

Perimeter is the length of the boundary of a two dimensional figure.

1 Solution of Homework

Calculating Area, Perimeter and Volume

Inverse Trig Functions

Mathematics (Project Maths Phase 1)

ChE-1800 H-2: Flowchart Diagrams (last updated January 13, 2013)

SOLVING TRIGONOMETRIC EQUATIONS

CIRCLE COORDINATE GEOMETRY

I PUC - Computer Science. Practical s Syllabus. Contents

2009 Chicago Area All-Star Math Team Tryouts Solutions

Section 7.2 Area. The Area of Rectangles and Triangles

*X100/12/02* X100/12/02. MATHEMATICS HIGHER Paper 1 (Non-calculator) MONDAY, 21 MAY 1.00 PM 2.30 PM NATIONAL QUALIFICATIONS 2012

Arithmetic Computation Test (ACT) Preparation Guide

7.4A/7.4B STUDENT ACTIVITY #1

Year 9 set 1 Mathematics notes, to accompany the 9H book.

x(x + 5) x 2 25 (x + 5)(x 5) = x 6(x 4) x ( x 4) + 3

ALGEBRA 2/TRIGONOMETRY

x 2 + y 2 = 1 y 1 = x 2 + 2x y = x 2 + 2x + 1

Review Sheet for Test 1

Student Outcomes. Lesson Notes. Classwork. Exercises 1 3 (4 minutes)

Objective: To distinguish between degree and radian measure, and to solve problems using both.

CS 261 Fall 2011 Solutions to Assignment #4

Algebra Geometry Glossary. 90 angle

The University of the State of New York REGENTS HIGH SCHOOL EXAMINATION MATHEMATICS B. Thursday, January 29, :15 a.m. to 12:15 p.m.

Semester 2, Unit 4: Activity 21

Kristen Kachurek. Circumference, Perimeter, and Area Grades Day lesson plan. Technology and Manipulatives used:

Advanced GMAT Math Questions

Week 13 Trigonometric Form of Complex Numbers

Programming the PIC18/ XC8 Using C- Coding Dr. Farahmand

Homework 2 Solutions

Chapter 13 Storage classes

Notes and questions to aid A-level Mathematics revision

1 Abstract Data Types Information Hiding

GAP CLOSING. 2D Measurement. Intermediate / Senior Student Book

28 CHAPTER 1. VECTORS AND THE GEOMETRY OF SPACE. v x. u y v z u z v y u y u z. v y v z

Mathematics Placement Examination (MPE)

Unit 3: Circles and Volume

Solving Equations and Inequalities

Sample Test Questions

The GED math test gives you a page of math formulas that

PROBLEM SET. Practice Problems for Exam #1. Math 1352, Fall Oct. 1, 2004 ANSWERS

Application Note: AN00141 xcore-xa - Application Development

Introduction to Scientific Computing Part II: C and C++ C. David Sherrill School of Chemistry and Biochemistry Georgia Institute of Technology

Euler s Formula Math 220

Unit 6 Trigonometric Identities, Equations, and Applications

Examples of Functions

Objective: Use calculator to comprehend transformations.

Biggar High School Mathematics Department. National 5 Learning Intentions & Success Criteria: Assessing My Progress

Additional Topics in Math

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Java Programming (10155)

SAT Subject Math Level 2 Facts & Formulas

WORK SCHEDULE: MATHEMATICS 2007

This activity will guide you to create formulas and use some of the built-in math functions in EXCEL.

Below is a very brief tutorial on the basic capabilities of Excel. Refer to the Excel help files for more information.

Section 7.1 Solving Right Triangles

ASSESSSMENT TASK OVERVIEW & PURPOSE:

LESSON 7 Don t Be A Square by Michael Torres

Trigonometric Functions: The Unit Circle

Programming a mathematical formula. INF1100 Lectures, Chapter 1: Computing with Formulas. How to write and run the program.

Determine If An Equation Represents a Function

NURBS Drawing Week 5, Lecture 10

Trigonometry Review with the Unit Circle: All the trig. you ll ever need to know in Calculus

Geometry - Calculating Area and Perimeter

MCA Formula Review Packet

INTERESTING PROOFS FOR THE CIRCUMFERENCE AND AREA OF A CIRCLE

One advantage of this algebraic approach is that we can write down

Metas.UncLib. Michael Wollensack und Marko Zeier. Metas Seminar Ein Messunsicherheitsrechner für Fortgeschrittene

ANALYTICAL METHODS FOR ENGINEERS

4. How many integers between 2004 and 4002 are perfect squares?

MS-EXCEL: ANALYSIS OF EXPERIMENTAL DATA

Angles and Quadrants. Angle Relationships and Degree Measurement. Chapter 7: Trigonometry

Functions and their Graphs

Transcription:

C Programming Language Lecture 4 (10/13/2000) Instructor: Wen-Hung Liao E-mail: whliao@cs.nccu.edu.tw Extension: 62028

Building Programs from Existing Information Analysis Design Implementation Testing 2

Case Study Finding the area and circumference of a circle Analysis: one input: radius two outputs: area, circumference Constant: PI Formula 3

Case Study: Initial Algorithm Get the circle radius Calculate the area Calculate the circumference Display the results 4

Case Study: Implementation /* Calculates and displays the area and circumference of a circle */ #include <stdio.h> #define PI 3.14159 int main(void) { double radius; /* input - radius of a circle */ double area; /* output - area of a circle */ double circum; /* output - circumference */ /* Get the circle radius */ /* Calculate the area */ /* Assign PI * radius * radius to area. */ /* Calculate the circumference */ /* Assign 2 * PI * radius to circum. */ /* Display the area and circumference */ } return (0); 5

Library Functions Pre-defined functions -> code reuse Example: sqrt(x) to compute the square root of #include <math.h> 6

C Mathematical Library Functions Function Header File Argument Result abs(x) <stdlib.h> int int ceil(x) <math.h> double double cos(x) <math.h> double double exp(x) <math.h> double double fabs(x) <math.h> double double floor(x) <math.h> double double log(x) <math.h> double double log10(x) <math.h> double double 7

More C Math Functions Function Header File Argument Result pow(x,y) <math.h> double, double double sin(x) <math.h> double double (radians) sqrt(x) <math.h> double double tan(x) <math.h> double (radians) double 8

Dealing with abnormalities What happens if you send a negative number as an argument to the function sqrt(x)? How about log10(x)? How about abs(5.6)? It s up to the programmer, not the compiler, to deal with these potential problems. 9

Mathematical Expressions Compute the value of a, given: a 2 = b 2 + c 2 2bc cos( α) b α a a=sqrt(b*b + c*c - 2*b*c*cos(alpha*PI/180.0)) c 10

Other Examples Evaluate ceil(-7.2)*pow(4.0,2.0) Write the expression for: ( x y) 3 11

Top-down Design Case study: drawing simple diagrams Problem: Draw simple diagrams, such as a house, on your screen. Analysis: draw figures with some basic components: a circle a base line parallel lines intersecting lines 12

Structure Chart Drawing Stick Figures Draw a figure Draw a circle Draw a triangle Draw intersecting lines Draw intersecting lines Draw a base 13

Function without arguments Example: void draw_circle(void) Function Prototypes (Important!) a function must be declared before it is referenced. One way to declare a function is to insert a function prototype before the main function. 14

Function Prototype Tells the C compiler the data type of the function, the function name, and information about the arguments that the function expects. Example: double sin(double x); double pow(double x, double y); 15

Example /* * Draws a circle */ void draw_circle(void) { printf(" * \n"); printf(" * *\n"); printf(" * * \n"); } 16

Draw a stick figure /* * Draws a stick figure */ #include <stdio.h> /* function prototypes */ void draw_circle(void); /* Draws a circle */ void draw_intersect(void); /* Draws intersecting lines */ void draw_base(void); /* Draws a base line */ void draw_triangle(void); /* Draws a triangle */ int main(void) { /* Draw a circle. */ draw_circle(); /* Draw a triangle. */ draw_triangle(); /* Draw intersecting lines. */ draw_intersect(); } return (0); 17

Functions with input arguments Void function with input arguments functions with input arguments and a single result functions with input arguments and multiple results (use pointer ) 18

Advantage of using functions Procedural abstraction Function reuse Easier to maintain, debug 19

Your Homework Read Chapter 3 of textbook Use the top-down design approach to write a C program that will print your initials (e.g., my name is Wen-Hung Liao, then I'll have to write three functions, draw_w( ), draw_h( ), and draw_l( ) and use a main program to call these functions to print out the letters.). 20

Your Homework (cont d) Write three functions, named dsin, dcos, and dtan, respectively, so that a user can pass the argument in degrees, instead of radians, to compute sin, cos, and tan. Use a main program to test your code. Due on 10/20/2000. Please send the source code to your TA via e-mail. 21