C primer plus(第五版)课后编程练习答案(完整)(14)
时间:2025-02-22
时间:2025-02-22
C primer plus(第五版)课后编程练习答案(完整)
while(i++<11)
{
printf("%d ",num++);
}
return(0);
}
3.编写一个程序,该程序要求用户输入天数,然后将该值转换为周数和天数。例如,此程序将把18天转换成2周4天。用下面的格式显示结果:
使用一个while循环让用户重复输入天数;当用户输入一个非正数(如0或-20)时,程序将终止循环。
#include<stdio.h>
#define WEEK 7
int main(void)
{
int days;
printf("Please input the days:");
scanf("%d",&days);
while(days>0)
{
printf("%d days are %d weeks,%d days.\n",days,days/WEEK,days%WEEK);
printf("Please input the days:");
scanf("%d",&days);
}
return(0);
}
4.编写一个程序让用户按厘米输入一个高度值,然后,程序按照厘米和英尺英寸显示这个高度值。允许厘米和英寸的值出现小数部分。程序允许用户继续输入,直到用户输入一个非正的数值。程序运行的示例如下面所示:
Enter a height in centimeters: 182
182.0 cm = 5 feet, 11.7 inches
Enter a height in centimeters(<=O to quit): 168
168.0 cm = 5 feet, 6.1 inches
Enter a height in centimeters(<=O to quit): 0