Advertisement
mercMatvey4

Untitled

Feb 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. //4.3
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. setlocale(LC_ALL,"");
  11. srand(time(0));
  12. int n;
  13. float sum{0};
  14. double mult{1};
  15. cout << "Количество элементов массива n : ";
  16. cin >> n;
  17. float arr[n];ы
  18. cout << "\nМассив arr : ";
  19. for (int i = 0; i < n; i++)
  20. {
  21. arr[i] = (rand() % 100) / 2.5;
  22. cout << arr[i] << " ";
  23. }
  24. for (int i = 0; i < n; i++)
  25. {
  26. if (i%2==0) mult *= arr[i];
  27. if (i%2!=0) sum += arr[i];
  28. }
  29. cout << "\n\nПроизведение четных элементов : " << mult;
  30. cout << "\n\nСумма нечетных элементов : " << sum << endl;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement