(编译环境 Microsoft Visual Studio 2019)
/*1.*/
#include
#define M_PER_H 60
int main(void)
{
int time;
int hour, minute;
printf("Please enter a time in minute.(<=0 to quit)\n");
scanf_s("%d", &time);
while (time > 0)
{
hour = time / M_PER_H;
minute = time % M_PER_H;
printf("the time is %d hours and %d minutes.\n", hour, minute);
printf("\nPlease enter a time in minute.(<=0 to quit)\n");
scanf_s("%d", &time);
}
printf("Done!\n");
return 0;
}
/*2.*/
#include
int main(void)
{
int value,object;
printf("please enter a integer.\n");
scanf_s("%d", &value);
object = value + 10;
while (value <= object)
{
printf("%d ", value);
value++;
}
printf("\n");
return 0;
}
/*3.*/
#include
#define A_WEEK 7
int main(void)
{
int time;
int weeks, days;
printf("Please enter a number of days.(<=0 to quit)\n");
scanf_s("%d", &time);
while (time > 0)
{
weeks = time / A_WEEK;
days = time % A_WEEK;
printf("%d days are %d weeks, %d days.\n", time, weeks, days);
printf("\nPlease enter a number of days.(<=0 to quit)\n");
scanf_s("%d", &time);
}
printf("Done!\n");
return 0;
}
/*4.*/
#include
#define C_PER_I 2.54f
#define I_PER_F 12
int main(void)
{
float height_c,height_i;
float inch;
int feet;
printf("Enter a height in centimeter:");
scanf_s("%f", &height_c);
while (height_c > 0)
{
height_i = height_c / C_PER_I;
feet = height_i / I_PER_F;
inch = height_i - (feet * I_PER_F);
printf("%.1f cm = %d feet ,%.1f inches\n", height_c, feet, inch);
printf("Enter a height in centimeter(<=0 to quit):");
scanf_s("%f", &height_c);
}
printf("bye\n");
return 0;
}
/*5.*/
#include
int main(void)
{
int object;
int count, sum;
count = 0;
sum = 0;
printf("Please enter a object.\n");
scanf_s("%d", &object);
while (count++ < object)
{
sum = sum + count;
}
printf("sum=%d\n", sum);
return 0;
}
/*6.*/
#include
int main(void)
{
int object;
int count, sum;
int square;
count = 0;
sum = 0;
printf("Please enter a object.\n");
scanf_s("%d", &object);
while (count++ < object)
{
square = count * count;
sum = sum + square;
}
printf("sum=%d\n", sum);
return 0;
}
/*7.*/
#include
void d_cube(double d);
int main(void)
{
double value;
printf("Please enter a double value.\n");
scanf_s("%lf", &value);
d_cube(value);
return 0;
}
void d_cube(double d)
{
long double cube;
cube = d * d * d;
printf("The cube is %le\n", cube);
}
/*8.*/
#include
int main(void)
{
int second, first;
printf("This program computes moduli.\n");
printf("Enter an integer to serve as the second operand: ");
scanf_s("%d", &second);
printf("Now enter the first operand: ");
scanf_s("%d", &first);
while (first > 0)
{
printf("%d %% %d is %d\n", first, second, first % second);
printf("Now enter the first operand(>=0 to quit): ");
scanf_s("%d", &first);
}
printf("Done!\n");
return 0;
}
/*9.*/
#include
void temperatures(double d);
int main(void)
{
double fahrenheit;
printf("Please enter a Fahrenheit temperature.(non-numeric to quit)\n");
while (1 == scanf_s("%lf", &fahrenheit))
{
temperatures(fahrenheit);
printf("\nPlease enter a Fahrenheit temperature.(non-numeric to quit)\n");
}
printf("bye\n");
return 0;
}
void temperatures(double d)
{
const float CF_FIRST = 5.0f / 9.0f;
const float CF_SECOND = 32.0f;
const float KC_TRANS = 273.16f;
double kelvin, celsius;
celsius = CF_FIRST * (d - CF_SECOND);
kelvin = celsius + KC_TRANS;
printf("Fahrenhrit temperature = %.2f\n", d);
printf("Celsius temperature = %.2f\n", celsius);
printf("Kelvin temperature = %.2f\n", kelvin);
}