45
โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ ชชชชชชชชชชชชชชชชชชช 6/1

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

Embed Size (px)

Citation preview

  • 1. 6/1

2. (Function) 3. type int ,float , char , double , void voidint function_name type parameterparameter, N parametervoid { location variable declaration statement_ ; statement_ ; ... statement_N return(value); 4. F N T N INC U C IO S CS A D R TNADPO RM E R G A MR LIBRARYDF E F N T N E IN D U C IO1. User-defined Function)2.Standard Function) include directives header file 5. 1.1.1type function_name(type1 arg1, type2 arg2,.., typeN argN){local variable declaration;statement(s);return( varlue);} 6. typetype int, float, chardoubleinttypevoidfunction_nametype1 arg1, type2 arg2,, typeN argN argument 1, 2, 3,, N void{}local variable declarationlocalstatement(s) 1; (semicolon)return(value) value () 7. #include#includevoid 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();}/* 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);} 8. 3 4 void one(void); void two(void);one( )two( ) void one( )two( ) void ()one( ) two argument main( )8 9one( );two( ); one( )two( ) one( )14 18 two( )20251418 one( )ab2025two( )p 9. 10. 1.22#include #include Main ()Main (){{Function-name2 (); Function-name1 ();... Function-name2Function-name1 (); ();}.. } 11. #include 12. 1.3()void function_name(void ) 13. #include#includevoid 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 */void asterisk_line( ){int j, n=40;for(j=1; jstrcpy string 1,string 2 strcat:string 2 string 1 strcat string 1,string 2 33. strcmp : string 1string 2 1 string 1 string 2 0 strcmp string 1,string 2strlen : strlen stringstrcmpi : string 1string 2 0 string 1< string 2 string 2 >0strcmpi string 1,string 2 34. 2.3#include TOLOWERLOWERTOLOWER(text) textTOUPPER UPPERLOWER TOUPPERTOUPPER(text) 35. 2 41.2.3. -4. 36. printf 37. 1.char s3[5] = {G, O, O, D, 0}; s3 ) ) ).. )2. ) ) ). )3. ) int function_name(type arg, ) ) void function_name(type arg, ) ) function_name(type arg, .) ) void function_name() 38. 4. ) ) ) )5. ) ) ) {} [] )6.char s1[9] = LANGUAGE; s1 ) ) ).. ) 39. 7. char s2[4] = {G, O, O, D}; s2 ) ) ).. )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() 40. 10.) strcmpstrcmp string 1,string 2) strcat strcat string 1,string 2) strcpystrcpy string 1,string 2) strlen strlen string 41. 1.2.3.4.5.6.7.8.9.10. 42. 1. 132.143. 194.215. 226.23 6/1