fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. // Example input array (real numbers)
  8. vector<double> arr = {0.5, 1.1, 2.0, 4.5, 5.2, 7.8};
  9. int n = arr.size();
  10. int K = 0;
  11.  
  12. cout << "Array elements: ";
  13. for (double x : arr) {
  14. cout << x << " ";
  15. }
  16. cout << endl;
  17.  
  18. cout << "Positions (starting from 1) where condition is met: ";
  19. // Start comparing from the second element (index 1)
  20. for (int i = 1; i < n; i++) {
  21. if (arr[i] < arr[i - 1]) {
  22. cout << (i + 1) << " "; // Output position (1‑based)
  23. K++;
  24. }
  25. }
  26. cout << endl;
  27.  
  28. cout << "Number of elements satisfying the condition K = " << K << endl;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Array elements: 0.5 1.1 2 4.5 5.2 7.8 
Positions (starting from 1) where condition is met: 
Number of elements satisfying the condition K = 0