Advertisement
Courbe_Impliquee

mas

Dec 13th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <time.h>
  5. #include <clocale>
  6. using namespace std;
  7. const int n = 10;
  8.  
  9. int _tmain(int argc, _TCHAR* argv[])
  10. {
  11. setlocale(LC_ALL, "rus");
  12. float a[n],sum=0,min,min2,sum2=0,t;
  13. for (int i = 0; i<n; i++){
  14. a[i] = rand() % 10 - 6.3;
  15. cout << setw(6)<< a[i];
  16. }
  17. cout << endl;
  18. for (int i = 0; i<n; i++){
  19. if (a[i]<0){
  20. min2 = i;
  21. }
  22. if (i % 2 == 1){
  23. sum += a[i];
  24. }
  25. }
  26. for (int i = 0; i<n; i++){
  27. if (a[i]<0){
  28. min = i + 1;
  29. break;
  30. }
  31. }
  32. for (int i = min; i<min2; i++){
  33. sum2 += a[i];
  34. }
  35. for (int i = 0; i < n; i++){
  36. if (abs(a[i]) < 1){
  37. a[i] = 0;
  38. }
  39. cout << setw(6) << a[i];
  40. }
  41. cout << endl;
  42. for (int i = 0; i < n; i++){
  43. for (int j = i + 1; j < n; j++){
  44. if (a[i] == 0){
  45. t = a[i];
  46. a[i] = a[j];
  47. a[j] = t;
  48. }
  49. }
  50. }
  51. for (int i = 0; i < n; i++){
  52. cout << setw(6) << a[i];
  53. }
  54. cout << endl;
  55. cout << "Сумма нечётных элементов :" << sum << endl;
  56. cout << "Сумма между первым и последним отрицательным"<<sum2<<endl;
  57. system("pause");
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement