5.1 循环简介——while循环
//计算多个不同鞋码对应的脚长
#include<stdio.h>
#define ADJUST 7.31 //字符常量
int main(void)
{
const double SCALE=0.333; //const常量
double shoe,foot;
shoe=8.0;
printf("shoe size (men's) foot length\n");
while(shoe<18.5) //while循环开始
{ //块开始
foot=SCALE*shoe+ADJUST;
printf("%10.1f %15.2f inches\n",shoe,foot);
//使用足够大的字段宽度可以让输出整齐美观
shoe=shoe+1;
} //块结束
printf("if the shoe fit,wear it.\n");
getchar();
return 0
输出结果
shoe size (men's) foot length
8.0 9.97 inches
9.0 10.31 inches
10.0 10.64 inches
11.0 10.97 inches
12.0 11.31 inches
13.0 11.64 inches
14.0 11.97 inches
15.0 12.31 inches
16.0 12.64 inches
17.0 12.97 inches
18.0 13.30 inches
if the shoe fit,wear it.