fork download
  1. #include <ctime>
  2. #include <cstdlib>
  3. #include <iomanip>
  4. #include <iostream>
  5. using namespace std;
  6. int nonInteger(double *a, int size, double *b){
  7. int r = 0;
  8. for (int i = size; i--; r += a[i] == (int)a[i]);
  9. if (b){
  10. r = 0;
  11. for (int i = size; i--;)
  12. if (a[i] == (int)a[i])
  13. b[r++] = a[i];
  14. }
  15. return r;
  16. }
  17. int main(){
  18. srand(time(NULL));
  19. size_t n = rand() % 20 + 1;
  20. double *a = new double[n];
  21. for (int i = 0; i < n; cout << fixed << setw(5) << setprecision(1) << (a[i] = rand() % 100 + rand() % 2 * 0.5), ++i);
  22. cout << endl;
  23. size_t k = nonInteger(a, n, NULL);
  24. double *b = new double[k];
  25. k = nonInteger(a, n, b);
  26. for (int i = 0; i < k; cout << fixed << setw(5) << setprecision(1) << b[i], ++i);
  27. delete a, b;
  28. return 0;
  29. }
Success #stdin #stdout 0s 4484KB
stdin
Standard input is empty
stdout
 32.0 91.5 36.5 85.5 75.0 12.0  9.5 74.0 40.0 48.0  1.0 37.5 54.0 63.0  0.0 84.5 95.0
 95.0  0.0 63.0 54.0  1.0 48.0 40.0 74.0 12.0 75.0 32.0