Upcoming SlideShare
×

# โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1

492 views

Published on

Published in: Education, Technology
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

### โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1

1. 1. 1. 132. 143. 194. 215. 226. 23
2. 2. 6/1 302121 2555
3. 3. 11-22
4. 4. 2- 2-4- 5- 6-7- 7- 8-9- 9-10- 10-1213- 13-15- 15-16- 16-17
5. 5. 1819-2020 mind map Function)
6. 6. type int , float ,char , double , void void int function_name type parameter parameter ,Nparameter void { location variable declaration
7. 7. statement_ ; statement_ ; ... statement_N return(value); void) return }1. User-definedFunction)2. Standard Function) include directives headerfile 1)
8. 8. type function_name(type1 arg1, type2 arg2,.., typeN argN) { local variable declaration; statement(s); return( varlue); }1.1type type int, float, chardouble int type voidfunction_nametype1 arg1, type2 arg2,…, typeN argN
9. 9. argument 1, 2,3,…, N void{}local variable declaration localstatement(s) 1 ; (semicolon)return(value)value ()#include<stdio.h>#include<conio.h>void one(void); /* function Prototypevoid two(void); /* function Prototypevoid main(void){clrscr();one(); /* call one() */two(); /* call two() */printf("nPress any key back to program ...");getch();}
10. 10. /* one function */void one() { int a=5, b=7; printf("A = %d, B = %dn",a,b); } /* two function */ void two() { float p=4.5, q=3.5; p+=q; printf("P = %6.3f, Q = %6.3fn",p,q); } • • • • – – – 1.2 2 1. 2. #include <stdio.h>
11. 11. Main () { Function-name2 (); …………………... Function-name1 (); } #include <stdio.h> Main () { Function-name1 (); Function-name2 (); ………………….. } 1. #include 2.1.3
12. 12. () void function_name(void )#include<stdio.h>#include<conio.h>void asterisk_line(void);void main(void){clrscr( );asterisk_line( );printf("****** C and C++ PROGRAMMING ******n");asterisk_line();printf("nPress any key back to program ...");getch();}/* asterisk_line function */
13. 13. void asterisk_line( ){int j, n=40;for(j=1; j<=n; j++)printf("*");printf("n");} 1.4 void function_name (type_parameter parameter_name [,..] ) ; function_ name type_parameter parameter_name 1 , #include <stdio.h>
14. 14. Void addition (int , int ) ; Void main () { Int a,b ; …….... Addition (a,b) ; } Void addition (int m , int n) { …............ }1.5 Type_variable function_name parameter_name,… ; Type_variable function_name
15. 15. parameter_name#include<stdio.h>#include<conio.h>int calculate(int, int);void main(void){int p=3, q=4, r;clrscr( );r = calculate(p,q);printf("P = %d, Q = %d, R = %dn",p,q,r);printf("nPress any key back to program ...");getch();} /* end main() */int calculate(int p, int q){
16. 16. return (p+q);} 1.6 variable_name = function_name(); variable_name return (value)
17. 17. 7 (Local Variable) (Global Variable)( ) /* 7th Sample Program: Local vs Global Variable */ #include<stdio.h> int ans = 0; int inc_one(int); /* function prototype */ void main() { int a = 3; ans = inc_one(a); printf(“Answer is %dn”, ans); } /* function definition: return x+1 */ int inc_one(int x) { int ans; ans = x + 1; return ans; }
18. 18. ans (main) ans a inc_one x ans ans ans inc_one ans inc_one ansinc_one ans ans C Header #include#include<stdio.h> Square root 4 = 2.000000 5 power 3 = 125.000000
19. 19. #include<math.h>void main(){ printf(“square root 4 =”); printf(“%fn”, sqrt(4)); printf(“5 power 3 =”); printf(“%f”, pow(5,3));} include .h • printf scanf include stdio.h • sqrt pow include math.h math.h double double
20. 20. sin(), cos() tan() sin(x) sine x cos(x) cosine x (radian) tan(x) tangent x (radian) sqrt(x) x x exp(x) ex e pow(x,y) xy log(x) log e natural logarithmx
21. 21. log10(x) log xceil(x) x xfloor(x) x xfabs(x)
22. 22. string.h)• string.h –strcat( 1, 2) –strcpy( , –strlen( –strcmp( 1, 2) -strcmpi ( 1, 2) 2.3 #include <ctype.h> TOLOWERLOWER TOLOWER(text)
23. 23. text TOUPPER UPPER LOWERTOUPPER TOUPPER(text) text
24. 24. 4 -4. –
25. 25. printf #include1. char s3[5] = {‘G’, ‘O’, ‘O’, ‘D’, ‘0’}; s3 ก. ข. ค. . . ง.2. ก. ข. ค. . ง.3.
26. 26. ก. int function_name(type arg, …) ข. void function_name(type arg, …) ค. function_name(type arg, ….) ง. void function_name()4. ก. ข. ค. ง.5. ก. ข. {} ค. [] ง. 6. char s1[9] = “LANGUAGE”; s1 ก. ข. ค. . . ง. 7. char s2[4] = {‘G’, ‘O’, ‘O’, ‘D’}; s2
27. 27. ก.ข.ค. . .ง.8.ก. function_name();ข. function_name()ค. function_name(arg1,arg2) Function_name(arg1; arg2);9.ก. int function_name(type arg, …)ข. void function_name(type arg, …)ค. function_name(type arg, ….) void function_name()10.ก. getchar()ข. gets()ค. fgets()ง. get ( 1. 6. 2. 7. 3. 8. 4. 9. 5. 10.
28. 28. . 7 C http://e-learning.snru.ac.th/els/program lesson page _ html21 2555. . . http://charinya-lru.com/charinyadocuments/subjects/ _ch _ppt.pdf 17 2555 http:// ~boonchoo/images/stories/ _function_I.pdf 19 2555 30201 http://www.gliffy.com 292555 http://uhost.rmutp.ac.th/kriengkri.l/w3.pdf 18 2555http://www.mk-job.com/bbs/thread-3897-1-1.html. 26 2555