Introduction to Computers and Programming Class 12 Introduction to C Professor Avi Rosenfeld.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

Chapter Five Functions
Case study 1: Calculate the approximation of Pi
Lab 8 User Defined Function.
BBS514 Structured Programming (Yapısal Programlama)1 Functions and Structured Programming.
1 ICS103 Programming in C Lecture 5: Introduction to Functions.
Introduction to Computers and Programming Lecture 11: Introduction to Methods Professor: Evan Korth New York University.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Section 6.3 Properties of the Trigonometric Functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
Function (L16) * Mathematical Library Functions * Program Components in C++ * Motivations for Functionalizing a Program * Function Prototype * Function.
 2007 Pearson Education, Inc. All rights reserved C Functions.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
CS100A, Fall 1997, Lectures 221 CS100A, Fall 1997 Lecture 22, Tuesday 18 November Introduction To C Goal: Acquire a reading knowledge of basic C. Concepts:
 2000 Prentice Hall, Inc. All rights reserved. Functions in C Outline 1Introduction 2Program Modules in C 3Math Library Functions 4Functions 5Function.
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.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 – Recursive Funtions From Deitel’s “C” Book 5.13Recursion 5.14Example Using Recursion: The Fibonacci.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Section 2.4 Library of Functions; Piecewise-defined Functions Instructor Dr. Sameh.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
EES Staff v10.0 Copyright © The Center for Educational Effectiveness, All Rights Reserved. EDUCATIONAL EFFECTIVENESS SURVEY TM Staff Survey 3-Way.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman CP 202 Chapter 3 Slides By Dr. Daniyal Alghazzawi.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 4 part 3 GEORGE KOUTSOGIANNAKIS.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Section 3.4 Library of Functions; Piecewise-defined Functions.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Section 3.4 Library of Functions; Piecewise-defined Functions.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Calculations Chapter Twelve. More serious than Chapter Four Page 199 some sizes (in bytes) of various primititive types: Do Not Memorize typeSize(bits)Approx.
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 5.3Math Library Functions Math library functions –perform.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions Outline 5.1Introduction 5.2Program Modules.
UniMAP SemI-09/10EKT120: Computer Programming1 Week 5 – Functions (1)
Section 6.2 Trigonometric Functions: Unit Circle Approach.
SubPrograms Top-Down Design using stepwise refinement leads to division of tasks.
Introduction to Programming Lecture 6. Functions – Call by value – Call by reference Today's Lecture Includes.
1 CSC103: Introduction to Computer and Programming Lecture No 9.
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.
Introduction to Programming
Mathematical Functions
Chapter 4 C Program Control Part I
Functions, Part 2 of 2 Topics Functions That Return a Value
Relational Operations
INC 161 , CPE 100 Computer Programming
Section R.8 nth Roots; Rational Exponents
Deitel- C:How to Program (5ed)
Functions.
Piecewise-defined Functions
Formatted and Unformatted Input/Output Functions
Functions Declarations CSCI 230
Java How to Program, Late Objects Version, 10/e
Lec 7.
Copyright © 2008 Pearson Prentice Hall Inc.
Copyright © 2008 Pearson Prentice Hall Inc.
Lecture4.
Mathematical Models: Building Functions
Copyright © 2008 Pearson Prentice Hall Inc.
Assignment Operators Topics Increment and Decrement Operators
Assignment Operators Topics Increment and Decrement Operators
Copyright © 2008 Pearson Prentice Hall Inc.
Computer Programming Techniques Semester 1, 1998
Piecewise-defined Functions
Assignment Operators Topics Increment and Decrement Operators
Copyright © 2008 Pearson Prentice Hall Inc.
Copyright © 2008 Pearson Prentice Hall Inc.
Presentation transcript:

Introduction to Computers and Programming Class 12 Introduction to C Professor Avi Rosenfeld

Math Functions Math.h Library –Sqrt –Pow –Fabs (absolute value) –Sin, Cos, Tan, etc.

Square Root Example #include #define number 2.0 void main() { printf("The square root of %.2f is %.2f\n", number, sqrt(number)); }

Power Example #include void main() { float base, exponent; printf("Please type a base followed by its exponent\n"); scanf("%f%f",&base, &exponent); printf("%.2f to the power of %.2f is %.2f\n", base, exponent, pow(base, exponent)); }

Loops and Sqrt #include void main() { for (int i = 100; i > 0; i--) printf("The square root of %d is %.2f\n", i, sqrt(i)); }

Nested Loops Logic within Logic –If / Loops (while, do while, for) inside of others Power Programming Technique

Nested While Loops #include void main() { int count1 = 0; while (count1 < 5) { int count2 = 0; while(count2 < 5) { printf("This is iteration %d within the bigger iteration %d\n",count2, count1); count2++; } count1++; }

Nested For Loops #include void main() { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) printf("*"); printf("\n"); }

Nested For Loops #2 #include void main() { for (int i = 0; i < 10; i++) { for (int j = 0; j <= i; j++) printf("%c", 'A'+j); printf("\n"); }

Deitel’s Example /* Fig. 4.6: fig04_06.c Calculating compound interest */ #include int main() { int year; double amount, principal = , rate =.05; printf( "%4s%21s\n", "Year", "Amount on deposit" ); for ( year = 1; year <= 10; year++ ) { amount = principal * pow( rate, year ); printf( "%4d%21.2f\n", year, amount ); } return 0; } /*********************************************************** *************** * (C) Copyright 2000 by Deitel & Associates, Inc. and Prentice Hall. * * All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * ********************************************************* ****************/

Program Ideas GPA calculator iloveny Diamond problems (see 4.16 in Deitel) Histograms (see 4.18) Drawing large letters (S, H, A) 4.11, 4.12, 4.13 in Deitel