Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. cout<<" Сумму модулей элементов массива, расположенных после последнего от-рицательного элемента";
  8. int kod,numb,summ=0;
  9. int size;
  10. cout <<endl<< "ВВедите размер массива:";
  11. cin >> size;
  12. int* array = new int[size];
  13. cout <<endl<< "Выберите способ заполнения массива";
  14. cout <<endl<< "0 -- Автоматический";
  15. cout <<endl<< "1 -- Ручной";
  16. cout <<endl<<"Выбор:";
  17. cin >> kod;
  18. switch(kod)
  19. {
  20. case 0:
  21. {
  22. for (int i=0; i<size;i++)
  23. {
  24. array[i]=rand()%11-5;
  25. cout<< array[i]<<" ";
  26. }
  27. break;
  28. }
  29. case 1:
  30. {
  31. cout <<endl<<"Введите массив:";
  32. for (int i=0; i<size;i++)
  33. {
  34. cin>>numb;
  35. array[i]=numb;
  36. }
  37. break;
  38. }
  39. }
  40. for (int i=size; i>0;i--)
  41. {
  42. if (array[i]<0) break;
  43. summ=summ+array[i];
  44. }
  45. cout<<endl<<"Ответ:" <<summ;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement