fork download
  1. #include <stdio.h>
  2.  
  3. char calc_grade(int score) {
  4. if(score >= 90) { return 'A'; }
  5. if(score >= 70) { return 'B'; }
  6. if(score >= 40) { return 'C'; }
  7. if(score >= 0) { return 'D'; }
  8. return '?';
  9. }
  10.  
  11. int main(void) {
  12. int values[] = {100, 90, 89, 70, 69, 40, 39, 0};
  13. for(int i = 0 ; i < sizeof(values) / sizeof(values[0]) ; i++) {
  14. int v = values[i];
  15. printf("%d = %c\n", v, calc_grade(v));
  16. }
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
100 = A
90 = A
89 = B
70 = B
69 = C
40 = C
39 = D
0 = D