fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. srand(time(NULL));
  11.  
  12. int n;
  13. cin >> n;
  14.  
  15. int index;
  16.  
  17. double tab[n];
  18. double min = (double)RAND_MAX;
  19. cout << fixed;
  20. for(int i = 0; i < n; i++)
  21. {
  22. tab[i] = (double)rand()/RAND_MAX;
  23. cout << setprecision(10) << tab[i];
  24. cout << ' ' << i << endl;
  25.  
  26. index = tab[i] < min ? i : index;
  27. min = tab[i] < min ? tab[i] : min;
  28. }
  29. cout << endl;
  30.  
  31. cout << setprecision(10) << min << ' ' << index << endl;
  32. }
Success #stdin #stdout 0s 3300KB
stdin
10
stdout
0.2705801876 0
0.1515762020 1
0.3446896152 2
0.4652620607 3
0.7906690085 4
0.7348879416 5
0.6948646212 6
0.0248044697 7
0.3445235516 8
0.9554139031 9

0.0248044697 7