Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <time.h>
- #include <clocale>
- using namespace std;
- const int n = 10;
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "rus");
- float a[n],sum=0,min,min2,sum2=0,t;
- for (int i = 0; i<n; i++){
- a[i] = rand() % 10 - 6.3;
- cout << setw(6)<< a[i];
- }
- cout << endl;
- for (int i = 0; i<n; i++){
- if (a[i]<0){
- min2 = i;
- }
- if (i % 2 == 1){
- sum += a[i];
- }
- }
- for (int i = 0; i<n; i++){
- if (a[i]<0){
- min = i + 1;
- break;
- }
- }
- for (int i = min; i<min2; i++){
- sum2 += a[i];
- }
- for (int i = 0; i < n; i++){
- if (abs(a[i]) < 1){
- a[i] = 0;
- }
- cout << setw(6) << a[i];
- }
- cout << endl;
- for (int i = 0; i < n; i++){
- for (int j = i + 1; j < n; j++){
- if (a[i] == 0){
- t = a[i];
- a[i] = a[j];
- a[j] = t;
- }
- }
- }
- for (int i = 0; i < n; i++){
- cout << setw(6) << a[i];
- }
- cout << endl;
- cout << "Сумма нечётных элементов :" << sum << endl;
- cout << "Сумма между первым и последним отрицательным"<<sum2<<endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement