第1题
/*编程练习5.1把分钟转化为小时和分钟*/
#include<stdio.h>
const int M_PER_H = 60; //每小时60分钟
int main(void)
{
int time,min, hour;
printf("Please input the time in minutes(<=0 to quit):\n");
scanf_s("%d", &time);
while (time > 0) {
hour = time / M_PER_H;
min = time % M_PER_H;
printf("The time is %d hours and %d minutes.\n", hour, min);
printf("Please input the time in minutes(<=0 to quit):\n");
scanf_s("%d", &time);
}
printf("Done!\n");
return 0;
}
第2题
/*编程练习5.2输入一个整数,打印该数及大10的数*/
#include<stdio.h>
int main(void)
{
int input, max;
printf("Print continue 10 numbers.\n");
printf("Please input the start number:\n");
scanf_s("%d", &input);
max = input + 10; //打印上限
while (input <= max) {
printf("%d\t", input);
input++;
}
printf("\nDone!")