Download - Processing 4th Class: Function
![Page 1: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/1.jpg)
어떻게 반복되는 작업을 처리할 것인가 ?
Function: 함수창의적공학설계입문 네번째 시간
![Page 2: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/2.jpg)
함수란 ?
Contents01 정의 및 전역 / 지역 변수
재귀 호출 (Recursion)02 함수의 반복 호출
번외 : 사진 삽입03
![Page 3: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/3.jpg)
3
스파게티 코드프로그램 작성하다 보면 , 수정하기 힘들정도로 복잡한 구조를 만들곤 합니다 .
![Page 4: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/4.jpg)
4
Function ( 함수 )
하나의 큰 프로그램에서 반복되는 부분을 함수로 정리할 수 있기 때문에 , 복잡한 작업을 단순하게 만들 수 있고 , 재사용할 수 있으며 , 오류를 줄일 수 있다 .
매개변수 : 보통 함수내부에서 필요한 값을 전달
Return 값 : 최종 결과 값으로 있을 수도 있고 없을 수 도 있다 .
함수 (function), 서브루틴(subroutine), 루틴 (routine), 메서드 (method), 프로시저(procedure)는 소프트웨어에서 특정 동작을 수행하는 일정 코드 부분을 의미한다 .
![Page 5: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/5.jpg)
5
함수의 구조
매개변수 : int 형 변수 num-ber 값을 준다
Return 값 : int 형 변수 number 를 반환한다
Return 타입
![Page 6: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/6.jpg)
6
예제 1: Return 이 있는 함수
![Page 7: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/7.jpg)
7
전역 변수와 지역 변수• 전역 변수는 어디에서든지 불러서 사용할 수 있다 .
• 지역변수는 선언된 블록 내에서만 사용 가능하다 .
![Page 8: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/8.jpg)
8
예제 2: 전역 변수와 지역 변수
![Page 9: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/9.jpg)
9
예제 3: 동심원 그리기
![Page 10: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/10.jpg)
10
예제 3: 실행화면
![Page 11: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/11.jpg)
11
예제 4: Factorial
7! = 7 * 6 * 5 * 4 * 3 * 2 * 1
![Page 12: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/12.jpg)
12
예제 5: Recursion
반복 작업을 줄이기 위해 사용한다
![Page 13: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/13.jpg)
13
예제 5: 실행화면
![Page 14: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/14.jpg)
14
예제 6: 사진 삽입
![Page 15: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/15.jpg)
15
예제 6: 실행화면
![Page 16: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/16.jpg)
16
예제 7: 사진 위에 도형 넣기
![Page 17: Processing 4th Class: Function](https://reader033.vdocuments.pub/reader033/viewer/2022042618/58a190061a28ab97118b49e3/html5/thumbnails/17.jpg)
17
예제 7: 실행화면