程序清单5.2_shoes2.c程序_《C Primer Plus》P88

// 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 条件为真(即条件成立时),
        循环执行,否则就退出循环。
-------------------------------------
*/


猜你喜欢

转载自blog.51cto.com/13555061/2134405