35657

Untitled

Nov 16th, 2023
993
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     const int size = 9;
  7.     double arr[size] = { -5.7, 6.0, 2, 0, -4.7, 6, 8.1, -4, 0 };
  8.  
  9.     double positive = 0;
  10.     for (int i = size - 1; i >= 0; i--) {
  11.         if (arr[i] > 0) {
  12.             positive = arr[i];
  13.             break;
  14.         }
  15.     }
  16.  
  17.     double negative = 0;
  18.     for (int i = 0; i < size; i++) {
  19.         if (arr[i] < 0) {
  20.             negative = arr[i];
  21.             break;
  22.         }
  23.     }
  24.     cout << "Last positive number: " << positive << endl;
  25.     cout << "First negatine number: " << negative << endl;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment