程序清單5.2_shoes2.c程序_《C Primer Plus》P88
阿新 • • 發佈:2018-06-30
getchar() \n 進行 初步了解 11.2 運行 plus In CA // shoes2.cpp : 定義控制臺應用程序的入口點。
//
/*
時間:2018年6月29日23時15分
代碼:程序清單5.2_shoes2.c程序_《C Primer Plus》P88
目的:初步了解 while 循環 (當條件成立時進行循環,否則就退出循環)
*/
#include "stdafx.h"
#define ADJUST 7.64
#define SCALE 0.325
int _tmain(int argc, _TCHAR* argv[])
{
double shoe, foot;
printf("Shoe size (men's) foot length\n");
shoe = 3.0;
while (shoe < 18.5) /* while 循環開始 */
{ /* 代碼塊開始 */
foot = SCALE*shoe + ADJUST;
printf("%10.1f %15.2f inches\n", shoe, foot);
shoe = shoe + 1.0;
} /* 代碼結束 */
printf("If the shoe fits, wear it.\n");
getchar();
return 0;
}
/*
在VS2010中運行結果:
-------------------------------------
Shoe size (men's) foot length
3.0 8.62 inches
4.0 8.94 inches
5.0 9.27 inches
6.0 9.59 inches
7.0 9.91 inches
8.0 10.24 inches
9.0 10.57 inches
10.0 10.89 inches
11.0 11.22 inches
12.0 11.54 inches
13.0 11.87 inches
14.0 12.19 inches
15.0 12.52 inches
16.0 12.84 inches
17.0 13.16 inches
18.0 13.49 inches
If the shoe fits, wear it.
-------------------------------------
總結:
當 while 條件為真(即條件成立時),
循環執行,否則就退出循環。
-------------------------------------
*/
程序清單5.2_shoes2.c程序_《C Primer Plus》P88