#define _CRT_SECURE_NO_WARNINGS #include//第一题 int main() { float a,max,b; printf("Enter a number: "); scanf("%f", &a); max = a; while (max > 0) { printf("Enter a number: "); scanf("%f", &b); if (b <= 0) break; if (b > max) max = b; } printf("The largest number entered was %-10g", max);//这个保留有效位数有点超出前六章的范围了 return 0; } //第二题 int main() { int m, n,a; printf("Enter two integers:"); scanf("%d%d", &m ,&n); a = m % n; do { m = n; n = a; a = m % n; } while (a != 0); printf("Createst common divisor: %g", n); return 0; } //第三题 int main() { int a, b, c, d, e,m,n; printf("Enter a fraction: "); scanf("%d/%d", &a, &b); m = a; n = b; c = m % n; do { n = c; m = n; c = m % n; } while (c != 0); d = a / n; e = b / n; printf("In lowest terms %d/%d", d , e); return 0; } //第四题 int main() { float commission, value = 0; do { printf("Enter value of trade: "); scanf("%f", &value); if (value == 0) return 0; if (value < 2500.00f) commission = 30.00f + .017f * value; else if (value < 6250.00f) commission = 56.00f + .0066f * value; else if (value < 20000.00f) commission = 76.00f + .0034f * value; else if (value < 50000.00f) commission = 100.00f + .0022f * value; else if (value < 500000.00f) commission = 155.00f + .017f * value; else commission = 255.00f + .0009f * value; if (commission < 39.00f) commission = 39.00f; printf("Commission: $%0.2fn", commission); } while (value != 0); return 0; } //第五题 int main() { int a = 0, b = 0, c = 0; printf("Enter a number:"); scanf("%d", &a); printf("The reversal is: "); do { b = a % 10; c = a / 10; if (b == 0) break; a = c; printf("%d", b); } while (1); return 0; } //第八题 int main() { int days, week=0,i=0; printf("Enter number of days in month: "); scanf("%d", &days); printf("Enter starting day of the week: "); scanf("%d", &week); for (i = 1;i <= week;i++) { printf(" "); } for (i = 1;i <= days;i++) { printf("%4d",i); if((i+week)%7==0) printf("n"); } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)