fork(35) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define CONST 1200
  5.  
  6. int is_first_closest(int values[], int n) {
  7. int dist = abs(values[0] - CONST);
  8. for (int i = 1; i < n; ++i) {
  9. if (abs(values[i] - CONST) < dist) {
  10. return 0;
  11. }
  12. }
  13. return 1;
  14. }
  15.  
  16. int main() {
  17. int values[3] = {900, 1050, 1400};
  18. if (is_first_closest(values, 3)) {
  19. printf("First value is closest.\n");
  20. } else {
  21. printf("First value is not closest.\n");
  22. }
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 1720KB
stdin
Standard input is empty
stdout
First value is not closest.