CHAPTER 3
AN INTRODUCTION TO FUNCTIONS

[IMAGE: An Quarter-Size Version of The Joy of C Front Cover]
This chapter finishes our tutorial introduction to C. We focus on user-defined functions, showing how we can define simple functions and use them to improve upon our earlier interest rate programs. Along the way, we cover function definitions, function calls, function prototypes, and function return values. We also introduce the process of compiling programs that contain functions defined in multiple source files. Finally, we demonstrate how using functions leads to more readable and maintainable programs, and we discuss how to test the functions we've written. By this chapter's end, you should feel comfortable constructing programs from functions you write yourself.

Jump to: [Previous Chapter | Next Chapter]


  1. WRITING OUR OWN FUNCTIONS
  2. SEPARATE COMPILATION
  3. SOME ADDITIONAL FEATURES OF FUNCTIONS

FunctionÀÇ Á¤ÀÇ ¹× »ç¿ë

¿¹1) ¿ùº°·Î ÀÌÀÚ °è»êÀ» ÇÏ´Â ÇÁ·Î±×·¥ (intrate7.c)

¿¹2) 2°³ÀÇ source fileµé·Î ±¸¼ºµÈ C ÇÁ·Î±×·¥ (irmain.c, irfuncs.c)

ÇÁ·Î±×·¡¹Ö ±â¹ý


½Ç½À)

  1. n, m µÎ Á¤¼ö¸¦ ÀÔ·ÂÇÏ¿© nºÎÅÍ m±îÁöÀÇ ¼ýÀÚÀÇ ÇÕÀ» ±¸ÇÏ´Â ÇÁ·Î±×·¥ ÀÛ¼º (0 < n, m < 1000).
  2. ´ÙÀ½ ¸ðÇüÀ» È­¸é¿¡ Ãâ·ÂÇ϶ó.
    *
   ***
  *****
 *******
*********



Assignment #3 (±â°£: 1ÁÖÀÏ)

ÇÁ·Î±×·¥ 1) CombinationÀ» °è»êÇÏ´Â ÇÁ·Î±×·¥À» ÀÛ¼ºÇ϶ó.
Combination function C(n, k) = n! / [k! * (n - k)!]

½ÇÇà °á°ú:

Enter number of objects in the set (n)? 5
Enter number to be chosen (k)? 3
C(5, 3) = 10

ÇÁ·Î±×·¥ 2) À§ ½Ç½À 2ÀÇ ¸ðÇü¿¡¼­ ¹Øº¯ÀÇ Å©±â¸¦ ÀÓÀÇÀÇ È¦¼ö¸¦ ÀÔ·Â¹Þ¾Æ ±×¸®´Â ÇÁ·Î±×·¥À¸·Î º¯°æÇÏ¿© ÀÛ¼ºÇ϶ó.


[ Table Of Contents | Previous Chapter | Next Chapter]