CHAPTER 4
NUMBERS

[IMAGE: An Quarter-Size Version of The Joy of C Front Cover]
This chapter delves into the details of C's numerical data types and arithmetic operators. We begin with the rules for composing identifiers and then move on to the various integer and real data types. We show how to create numerical constants and declare numerical variables and how to read and print these values. Along the way we study the range of values each type can hold, and when each type is most appropriate. After looking at the numerical data types, we introduce C's arithmetic operators and examine conversions between different data types. The chapter concludes with a case study that converts decimal numbers to other bases.

Jump to: [Previous Chapter | Next Chapter]


  1. IDENTIFIERS AND NAMING CONVENTIONS
  2. INTEGERS
  3. REALS
  4. ARITHMETIC OPERATORS
  5. TYPE CONVERSIONS
  6. CASE STUDY: A BASE CONVERSION PROGRAM

C ProgramÀÇ ±¸¼º

ÄÄÇ»ÅÍÀÇ ¼ö ó¸® ü°è

¼ýÀÚÇü ÀÚ·áó¸®

¾ç½Ä¿¡ µû¸¥ ÀÔÃâ·Â

Math °ü·Ã standard library functions


½Ç½À

1. ½Ç¼ö x¿Í Á¤¼ö nÀ» ÀÔ·Â¹Þ¾Æ xÀÇ n½Â °ªÀ» printÇÏ´Â programÀ» ÀÛ¼ºÇ϶ó.
Function prototype: double power(double x, int n);
(nÀº À½¼ö°¡ µÉ ¼öµµ ÀÖÀ½)

2. 10Áø¼ö x¸¦ ÀÓÀÇÀÇ nÁø¼ö·Î º¯È¯ÇÏ´Â ÇÁ·Î±×·¥À» ÀÛ¼ºÇ϶ó. (convert.c¿Í convfnc.c ÂüÁ¶)

3. °¢µµ¸¦ ÀÔ·Â¹Þ¾Æ ±× °¢ÀÇ sin, cos, tan °ªµéÀ» Ãâ·ÂÇÏ´Â ÇÁ·Î±×·¥À» ÀÛ¼ºÇ϶ó.
sin, cos, tan ÇÔ¼ö´Â ÆĶó¹ÌÅÍ·Î ¶óµð¾È(radian) °ªÀ» »ç¿ëÇÑ´Ù. ÆÄÀÌ °ªÀº "math.h"¿¡ M_PI·Î #define µÇ¾î ÀÖ´Ù.
radian = angle * M_PI / 180.0


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

ÇÁ·Î±×·¥ 1) ÀÌÂ÷¹æÁ¤½Ä ax2 + bx + c = 0 ÀÇ ¼¼ coefficients (a, b, c) °ªÀ» ÀÐ°í ±ÙÀ» Ãâ·ÂÇÏ´Â ÇÁ·Î±×·¥À» ÀÛ¼ºÇ϶ó. (±Ù ¾øÀ½, Áß±Ù, º¹±ÙÀÇ °æ¿ì¸¦ °¢°¢ ó¸®ÇÒ °Í)

½ÇÇà °á°ú:

Coefficients (a, b, c)¸¦ ÀÔ·ÂÇϽÿÀ? 1.0 2.0 1.0
ÀÌÂ÷¹æÁ¤½Ä 1.0*x*x + 2.0*x + 1.0 = 0ÀÇ ±ÙÀº
Áß±Ù: -1.0

ÇÁ·Î±×·¥ 2) ¼öÇ¥ Ãâ·Â ÇÁ·Î±×·¥À» ÀÛ¼ºÇ϶ó.


[ Table Of Contents | Previous Chapter | Next Chapter]