1 / 21

SW-5WEEK

SW-5WEEK. 010-6385-0051 KJS. 함수. 프로그램 – 함수 컴퓨터 – 부품 main 함수 - 기타함수 표준 함수 사용자정의 함수. 함수. type name( 인수 목록 ) { 함수의 본체 } type – 함수의 작업 결과 , 리턴하는 값의 데이터형 name – 함수의 이름 인수 목록 – 함수가 실행하는 작업에 필요한 값 함수의 본체 – 함수가 실행하는 기능. 함수. 함수의 사용 – 1) #include< stdio.h >

eden
Download Presentation

SW-5WEEK

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. SW-5WEEK 010-6385-0051 KJS

  2. 함수 • 프로그램 – 함수 • 컴퓨터 – 부품 • main 함수 - 기타함수 • 표준 함수 • 사용자정의 함수

  3. 함수 type name(인수 목록) { 함수의 본체 } • type – 함수의 작업 결과, 리턴하는 값의 데이터형 • name – 함수의 이름 • 인수 목록 – 함수가 실행하는 작업에 필요한 값 • 함수의 본체 – 함수가 실행하는 기능

  4. 함수 • 함수의 사용 – 1) #include<stdio.h> int sum( int num ); void main(void) { … sum(4); …} int sum( int num ) { … }

  5. 함수 • 함수의 사용 – 2) #include<stdio.h> int sum( int num ) { … } void main(void) { … sum(4); …}

  6. 함수 #include<stdio.h> intfunc(int num) { return num; } void main(void) { int result; result = func(4); result = func(5,4); result = func(); }

  7. 함수 • 인수 – 실인수, 형식인수 #include<stdio.h> intfunc( int num ) { return num; } void main(void) { intresult, a = 5; result = func( a ); }

  8. 함수 • 전역변수 / 지역변수

  9. 함수

  10. 함수 #include<stdio.h> int global; intfunc() { int I; …} void main() { int local; … }

  11. 함수 #include<stdio.h> void test ( int a, int b) { printf("test, \n" ); } void main(void) { int a = 10; int b = 20; test ( a, b ); }

  12. 함수 • error int sum( int n1, int n2 ) { int n1, n2; } void main(void){ … }

  13. 함수 • 함수의 리턴 • 하나의 값만 리턴 가능 • 자료형이 일치하면수식내에서 바로 사용이 가능 • 리턴 값을 곧바로 사용할 수 있다. • 함수의 강제종료 • gotoxy(Max(a,b), Add(c,d)); • Add(Add(Add(Add(1,2),3),4),5);

  14. 함수 intadd(int x, int y) { int sum = x+y; return sum; }

  15. 함수 void result_print( intval ) { printf(“ 덧셈결과 : %d\n”,val); }

  16. 함수 int input(void) { int input; scanf( “ %d”, &input); return input; }

  17. 함수 void intro(void) { printf(“ START”); } • void형 함수

  18. 함수 - 재귀함수 #include<stdio.h> int up5(int a) { int b; if(a==0) return 1; else { b= a * up5(a-1); return b; } } main() { int result = up5(5); printf(" %d ", result ); }

  19. 함수 #include <stdio.h> void increment1(int number) { ++number; } void main(void) { int number = 10; printf(" number = %d\n\n", number); increment1(number); printf(" number = %d\n\n", number); }

  20. 함수 #include<stdio.h> void swap ( int a ,int b) { int temp = a; a = b; b = temp; } void main(void) { int a = 1; int b = 2; printf (" a = %d, b = %d \n", a, b ); swap( a, b ); printf (" a = %d, b = %d \n ", a, b ); }

  21. Homework – 5week • 3주차 과제를 재귀함수를 이용하여 작성.

More Related