fork(2) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <float.h>
  5.  
  6. #define EPSILON 0.00000001
  7.  
  8. static int compare(double num1, double num2, double error)
  9. {
  10. if(fabs(num1-num2) <= DBL_EPSILON)
  11. return 1;
  12. else
  13. return 0;
  14. }
  15.  
  16. static int areEqual(const double *x, int size, double error)
  17. {
  18. int i;
  19. for (i = 0; i < size - 1; i++)
  20. if (!compare(x[i], x[i + 1], error))
  21. return 0;
  22. return 1;
  23. }
  24.  
  25. int main(int argc, char **argv)
  26. {
  27.  
  28. double tab[] = {9.2, 9.7, 9.3, 9.6, 9.4, 10.0, 9.1, 9.7};
  29. double error = 0.8;
  30. const int N = 8;
  31.  
  32. printf("%d\n", areEqual(tab, N, error));
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
0