P114 编程练习1:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#define hour 60
int main()
{
int hours;
int minutes;
int part;
int minute;
while (1)
{
printf("Please enter minutes which you want calculation:");
scanf("%d", &minutes);
if (minutes <= 0)
break;
hours = minutes / hour;
part = minutes % hour;
printf("The time is equal to %d hours and %d minutes\n", hours, part);
}
return 0;
}
P114 编程练习2:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
int a;
int b;
scanf("%d", &a);
b = a+1;
while ((b <= (a + 10))&&(b>=a))
{
printf("%d ", b);
b++;
}
}
P114 编程练习3:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#define week 7
int main()
{
int days;
int weeks;
int day;
printf("Please enter the days:");
while ((scanf("%d", &days))&&days>0)
{
weeks = days / week;
day = days % week;
printf("days are equal to %d weeks and %d day\n", weeks,day);
printf("Please enter the days:");
}
}
P115 编程练习4:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#define inche 2.54
#define feet 30.48
int main()
{
double height;
double feets;
double inches;
printf("Please enter your height:");
while ((scanf("%lf", &height)) && height >= 1)
{
printf("Your height is %.1lf cm\n", height);
feets = height / inche;
printf("Your height are %1.1lf feets\n", feets);
inches = height / feet;
printf("Your height are %1.1lf inches\n", inches);
}
return 0;
}
P115 编程练习5:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
int count,sum;
count = 0;
sum = 0;
int days;
scanf("%d", &days);
while (count++ < days)
sum = sum + count;
printf("sum=%d\n", sum);
return 0;
}
P115 编程练习6:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
int count,sum,all;
count = 0;
sum = 0;
int days;
scanf("%d", &days);
while (count++ < days)
sum = sum + (count*count);
printf("sum=%d\n", sum);
return 0;
}
P115 编程练习7:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
void cube();
int main()
{
cube();
return 0;
}
void cube()
{
double a;
double b;
scanf("%lf", &a);
b = a * a * a;
printf("b=%lf", b);
}
P115 编程练习8:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
int a;
int b;
int c;
printf("This program computes moduli.\n");
printf("Enter an integer toserve as the second operand:");
scanf("%d", &a);
printf("Now enter the first operand:");
scanf("%d", &b);
c = b % a;
printf("c is %d\n", c);
while (a>0 && b>0)
{
printf("Now enter the next operand(<=0 to quit):");
scanf("%d", &b);
if (b <= 0) printf("done");
else
{
c = b % a;
printf("c is %d\n",c);
}
}
return 0;
}
P115 编程练习9:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
void Temperatures();
int main()
{
double Htem;
printf("The temperatures is:");
Temperatures();
return 0;
}
void Temperatures()
{
double Ktem;
double Stem;
double Htem;
while ((scanf("%lf", &Htem) == 1))
{
Stem = 5.0 / 9.0 * (Htem - 32.0);
Ktem = Stem + 273.16;
printf("temperatures in Stem is %lf\n", Stem);
printf("temperatures in Ktem is %lf:\n", Ktem);
}
}