Gilthawk23

циклы

Nov 25th, 2020
561
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 1
  2. #include <iostream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int number, sum = 0;
  9.     for (int i = 0; i < 10; i++) {
  10.         cin >> number;
  11.         if ((number > 0) && ((number % 10 == 5) || (number % 10 == 8))) { sum++; }
  12.     }
  13.     cout << sum << endl;
  14. }
  15.  
  16. // 2
  17. #include <iostream>
  18. #include <cstdlib>
  19.  
  20. using namespace std;
  21.  
  22. int main() {
  23.     int number, sumofpositive = 0, sumofnegative = 0;
  24.     for (int i = 0; i < 10; i++) {
  25.         cin >> number;
  26.         if (number > 0) { sumofpositive++; }
  27.         else if (number < 0) { sumofnegative ++; }
  28.     }
  29.     cout << "sum of negative numbers= " << sumofnegative << endl;
  30.     cout << "sum of positive numbers= " << sumofpositive << endl;
  31. }
RAW Paste Data