fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int N, X, Y;
  5. printf("請輸入 N、X、Y (0 < Y): ");
  6. scanf("%d %d %d", &N, &X, &Y);
  7.  
  8. int temperature = 20;
  9.  
  10. // 使用循環計算最高溫度
  11. for (int i = 0; i < N / 2; i++) {
  12. temperature += X;
  13. temperature -= Y;
  14. if (temperature < 20) {
  15. temperature = 20;
  16. }
  17. }
  18.  
  19. printf("%d\n", temperature);
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0.01s 5408KB
stdin
4 20 3
stdout
請輸入 N、X、Y (0 < Y): 54