#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
int n;
double sum = 0;
double multiply = 1;
cout << "Enter n = ";
cin >> n;
double *mas = mas = new double[n];
for (int i = 0; i < n; ++i)
mas[i] = -50 + (double)(rand() % 10001) / 100;
cout << mas[i] << " ";
}
for (int i = 0; i < n; i++)
if (mas[i] < 0)
multiply *= mas[i];
else
sum += mas[i];
cout << "sum positive = " << sum << endl;
cout << "multiply negative = " << multiply << endl;
system("pause");
Объяснение:
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <iomanip>
//#define int long long
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int mx = -INT_MAX,cnt=0,ans=1;
for(int i = 0; i < n; i++)
int k;
cin >> k;
if(i < n/2)
mx = max(mx,k);
if(k < 0)
ans *= k;
cnt++;
cout << "maximal element in first half: " << mx << "\n";
cout << "product of negative numbers: " << ans << "\n";
cout << "amount of negative numbers: " << cnt;
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
int n;
double sum = 0;
double multiply = 1;
cout << "Enter n = ";
cin >> n;
double *mas = mas = new double[n];
for (int i = 0; i < n; ++i)
{
mas[i] = -50 + (double)(rand() % 10001) / 100;
cout << mas[i] << " ";
}
for (int i = 0; i < n; i++)
{
if (mas[i] < 0)
multiply *= mas[i];
else
sum += mas[i];
}
cout << "sum positive = " << sum << endl;
cout << "multiply negative = " << multiply << endl;
system("pause");
}
Объяснение:
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <iomanip>
#include <map>
using namespace std;
//#define int long long
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int mx = -INT_MAX,cnt=0,ans=1;
for(int i = 0; i < n; i++)
{
int k;
cin >> k;
if(i < n/2)
mx = max(mx,k);
if(k < 0)
{
ans *= k;
cnt++;
}
}
cout << "maximal element in first half: " << mx << "\n";
cout << "product of negative numbers: " << ans << "\n";
cout << "amount of negative numbers: " << cnt;
}