#include <iostream>
using namespace std;
int main()
{
int sum = 0;
int composition = 1;
bool plusSeq = 1;
int n = 0;
cout << "Size array - ";
cin >> n;
int* a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = -10 + rand() % 21;
sum += a[i];
composition *= a[i];
cout << a[i] << " ";
}
for (int i = 0; i < n; i++)
{
if (a[i] < 0)
a[i] *= a[i];
}
for (int i = 1; i < n; i++)
{
if (a[i] < a[i - 1])
{
plusSeq = 0;
break;
}
}
if (plusSeq)
cout << "\nSum = " << sum;
else
cout << "\nComposition = " << composition;
delete[]a;
return 0;
}
Объяснение:
#include <iostream>
using namespace std;
int main()
{
int sum = 0;
int composition = 1;
bool plusSeq = 1;
int n = 0;
cout << "Size array - ";
cin >> n;
int* a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = -10 + rand() % 21;
sum += a[i];
composition *= a[i];
cout << a[i] << " ";
}
for (int i = 0; i < n; i++)
{
if (a[i] < 0)
a[i] *= a[i];
}
for (int i = 1; i < n; i++)
{
if (a[i] < a[i - 1])
{
plusSeq = 0;
break;
}
}
if (plusSeq)
cout << "\nSum = " << sum;
else
cout << "\nComposition = " << composition;
delete[]a;
return 0;
}
Объяснение:
var x:array[1..n] of real;
i:integer; min:real;
begin
for i:=1 to n do
begin
write('x[',i,']=');
readln(x[i]);
end;
min:=x[1];
for i:=2 to n do
if x[i]<min then min:=x[i];
for i:=1 to n do
if x[i]<0 then x[i]:=min;
for i:=1 to n do write(x[i],' ');
writeln;
end.