5.11.1
#include#define N 60 int main() { float min, hour, sec; printf("Please enter minute(<=0 quit):"); scanf_s("%f", &min); while (min > 0) { hour = min / N; sec = min * N; printf("There are %.2f hours.n", hour); printf("There are %.0f seconds.n", sec); printf("n"); printf("Please enter minute(<=0 quit):"); scanf_s("%f", &min); } printf("That's over."); return 0; }
5.11.2
#includeint main() { int num, tempnum; printf("Please enter a integer:"); scanf_s("%d", &num); tempnum = num + 10; while (num <= tempnum) { printf("%dn", num); // n or t or ' ' num++; } }
5.11.3
#includeint main() { int day, week, rest_day; printf("Please enter day number:"); scanf_s("%d", &day); while (day > 0) { week = day / 7; rest_day = day % 7; printf("%d days are %d weeks, %d days.n", day, week, rest_day); printf("nPlease enter day number:"); scanf_s("%d", &day); } printf("Wrong day number, over."); return 0; }
5.11.4
#include#include #define N 2.54 //一英寸的厘米数 #define M 12 //一英尺的英寸数 int main() { float height, feet, inch; printf("Enter a height in centimeters: "); scanf_s("%f", &height); while (height > 0) { inch = height / N; feet = (int)(inch / M); inch = inch - M*feet; printf("%.1f cm = %.0f feet, %.1f inches",height, feet, inch); printf("nEnter a height in centimeters (<=0 to quit):"); scanf_s("%f", &height); } printf("bye"); return 0; }
5.11.5
#includeint main() { int day, money = 0; int i = 1; printf("Please enter the day number: "); scanf_s("%d", &day); while (i <= day) { money += i; i++; } printf("The money you earn is: $%d", money); return 0; }
5.11.6
#includeint main() { int day, money = 0; int i = 1; printf("Please enter the day number: "); scanf_s("%d", &day); while (i <= day) { money += i * i; i++; } printf("The money you earn is: $%d", money); return 0; }
5.11.7
#includevoid cube(double NUM) { NUM = NUM * NUM * NUM; printf("The cube of number is: %.2f", NUM); } int main() { double num; printf("Please enter a float number:"); scanf_s("%lf", &num); cube(num); return 0; }
5.11.8
#includeint main() { int fstnum, secnum, trdnum; printf("This program computes moduli.n"); printf("Enter an integer to serve as the second operand: "); scanf_s("%d", &secnum); printf("Now enter the first operand: "); scanf_s("%d", &fstnum); while (fstnum > 0) { trdnum = fstnum % secnum; printf("%d %% %d is %dn", fstnum, secnum, trdnum); printf("Enter next number for first operand (<= 0 to quit): "); scanf_s("%d", &fstnum); } printf("Done."); return 0; }
5.11.9
#includevoid Temperatures(double Fdegree) { double Cdegree, Kdegree; Cdegree = 5.0 / 9.0 * (Fdegree - 32.0); Kdegree = Cdegree + 273.16; printf("The centiagred temperatures is: %.2f^Cn", Cdegree); printf("The Kelvin temperatures is : %.2fKn", Kdegree); } int main() { double fdegree; int judge; printf("Please enter Fahrenheit degree: "); judge = scanf_s("%lf", &fdegree); while (judge == 1) { Temperatures(fdegree); printf("Please enter next Fahrenheit degree: "); judge = scanf_s("%lf", &fdegree); } printf("Done."); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)