// shoes2.cpp : 定義控制檯應用程序的入口點。 // /* shoes2.c -- 計算多個鞋尺碼對應的英寸長度 */ /* 時間: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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.