shoes1.c & shoes2.c

This commit is contained in:
wandoubaba517 2023-12-07 19:03:38 +08:00
parent 9a08a37e8a
commit 6e9110b590
2 changed files with 39 additions and 0 deletions

17
c05_expression/shoes1.c Normal file
View File

@ -0,0 +1,17 @@
/* shoes1.c - 把鞋码转换成英寸 */
#include <stdio.h>
#define ADJUST 7.31
int main(void)
{
const double SCALE = 0.333;
double shoe, foot;
shoe = 9.0;
foot = SCALE * shoe + ADJUST;
printf("Shoe size (men's)\tfoot length\n");
printf("%10.1f\t%15.2f inches\n", shoe, foot);
return 0;
}

22
c05_expression/shoes2.c Normal file
View File

@ -0,0 +1,22 @@
/* shoes2.c - 计算多个不同鞋码对应的脚长 */
#include <stdio.h>
#define ADJUST 7.31
int main(void)
{
const double SCALE = 0.333;
double shoe, foot;
printf("Shoe size (men's)\tfoot length\n");
shoe = 3.0;
while (shoe < 18.5)
{
foot = SCALE * shoe + ADJUST;
printf("%10.1f\t%15.2f inches\n", shoe, foot);
shoe = shoe + 1.0;
}
printf("If the shoe fits, wearit.\n");
return 0;
}