1 / 10

Chapter 11

Chapter 11. Functions. 11.1 Functions. Why functions? sin(x),sqrt(x), … Structural programming Maintenance. 11.2 System Functions. Pseudo Number Generator #include <stdlib.h> rand(), srand(),randomize() Numerical #include <math.h>

kaden
Download Presentation

Chapter 11

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 11 Functions Windows Programming, C.-S. Shieh, KUAS EC, 2005

  2. 11.1 Functions • Why functions? • sin(x),sqrt(x), … • Structural programming • Maintenance Windows Programming, C.-S. Shieh, KUAS EC, 2005

  3. 11.2 System Functions • Pseudo Number Generator • #include <stdlib.h> • rand(), srand(),randomize() • Numerical • #include <math.h> • fabs(), pow(), sqrt(), sin(), cos(), tan(), asin(), acos(), atan(), exp(), log(), log10(), ceil(), floor() Windows Programming, C.-S. Shieh, KUAS EC, 2005

  4. 11.2 System Functions (cont) • Clock • #include <time.h> • clock(), time() Windows Programming, C.-S. Shieh, KUAS EC, 2005

  5. 11.3 User Defined Functions int sum(int i, int j) { int k; k=i+j; return(k); } void main(void) { printf(“%d”,sum(5,4)); } Windows Programming, C.-S. Shieh, KUAS EC, 2005

  6. 11.4 Parameter Passing • Call-by-Value int sum(int i, int j) { int k; k=i+j; return(k); } void main(void) { int x=5; int y=4; printf(“%d”,sum(x,y)); } Windows Programming, C.-S. Shieh, KUAS EC, 2005

  7. 11.4 Parameter Passing (cont) • Call-by-Address void inc(int i) void inc(int* ip) { { i++; (*ip)++; } } void main(void) void main(void) { { int i=1; int i=1; inc(i); inc(&i); printf(“%d”,i); printf(“%d”,i); } } Windows Programming, C.-S. Shieh, KUAS EC, 2005

  8. 11.5 Passing Array as Parameter void sort(int x[10]) { … } void main(void) { int x[10]={5,7,3,45,8,5,4,24,67,23}; sort(x); } Windows Programming, C.-S. Shieh, KUAS EC, 2005

  9. 11.6 Recursive Functions • Recursive Function • Recursive Relation • Terminate Condition • Fabonacci function long fabo(long i) { if(i==0) return 0; if(i==1) return 1; if(i>=2) return fabo(i-1)+fabo(i-2); } Windows Programming, C.-S. Shieh, KUAS EC, 2005

  10. Console Applications • Develop console applications using Borland C++Builder • FileNew…Console Wizard Windows Programming, C.-S. Shieh, KUAS EC, 2005

More Related