Fiind dat un vector cu n componente nr R determinati:
1
1) Suma componentelor vectorului
2)Produsul componentelor vectorului
3)Media aritmetica
4)Mediea armonica
5)Maximul (minimul)
6)Lista ordonate crescator si descrescator a componentelor vectorului
Răspunsuri la întrebare
Răspuns:
#include <iostream>
using namespace std;
int main()
{
int n;
double v[100001];
double s = 0, p = 1;
double mA, ma;
double Max=-999999999, Min=999999999999;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> v[i];
}
for (int i = 1; i <= n; i++)
{
s += v[i];
p *= v[i];
mA = s / n;
ma = n / s;
if (v[i] > Max)
Max = v[i];
else
if (v[i] < Min)
Min = v[i];
}
for (int i = 1; i <= n; i++)
{
for (int j = i + 1; j <= n; j++)
{
if (v[j]<v[i])
{
double aux;
aux = v[i];
v[i] = v[j];
v[j] = aux;
}
}
}
cout << s << '\n';
cout << p << '\n';
cout << mA << '\n';
cout << ma << '\n';
cout << Max << " " << Min << '\n';
for (int i = 1; i <= n; i++)
{
cout << v[i]<<" ";
if (i == n)
cout << '\n';
}
for (int i = 1; i <= n; i++)
{
for (int j = i + 1; j <= n; j++)
{
if (v[j] > v[i])
{
double aux;
aux = v[i];
v[i] = v[j];
v[j] = aux;
}
}
}
for (int i = 1; i <= n; i++)
{
cout << v[i] << " ";
}
}
//m-a capiat problema asta :)))
{
for (int j = i + 1; j <= n; j++)
{
if (v[j]
{
double aux;
aux = v[i];
v[i] = v[j];
v[j] = aux;
}
}
}