#include
using namespace std;
int main ()
{
float a[] = {5.75, -6, 3.4, -2.5, 3.6},
b[] = {-3.4, -0.5, 8.45, 4.3, 5.6};
cout<< "a[] massivelementlari :";
cout<
for(inti = 0; i< 5; i++)
{
cout<< a[i] << " ";
}
cout<
cout<
cout<< "b[] massivelementlari :";
cout<
for(inti = 0; i< 5; i++)
{
cout<< b[i] << " ";
}
cout<
cout<
float c[5];
cout<< "c[] massivelementlari :";
cout<
float s = 0;
for(inti = 0; i< 5; i++)
{
c[i] = (a[i] + b[i])/(a[i] * a[i] + sqrt(b[i]));
cout<< c[i] << " ";
s += c[i] * c[i];
}
cout<< s;
}
2-masala
Musbat va manfiy elementlarlardan iborat Y = {-5,1; 18; 75; 0,1; -17; 2,5; 6,35; 17,8} massiv berilgan. Massivning manfiy elementlarining ko‘paytmasini hisoblang va chop eting.
|
#include
using namespace std;
int main ()
{
float y[] = {-5.1, 18, 75, 0.1, -17, 2.5, 6.35, 17.8}
float p = 1;
for(inti = 0; i< 8; i++)
{
if(y[i] < 0)
{
p *= y[i];
}
}
cout<< "Berilganmassivningmanfiyelementlariningko'paytmasi " << p << " gateng" <
}
3-masala
U(K)massivining musbat, toq indeksli elementlarining yig‘indisini toping.
|
#include
using namespace std;
int main ()
{
float a[100];
int n;
cout<< " Massivelementlarisoninikiritng : " <
cout<< " n = " << n; cin>> n;
cout<< " Massivelementlarinikiriting : ";
for ( inti = 0; i< n; i++)
{
cout<< " a[ "<
cin>> a[i];
}
float s = 0;
for(inti = 1; i< n; i += 2)
{
if(a[i] > 0)
{
s += a[i];
}
}
cout<< "Berilganmassivningmusbattoqelementlariningyig'indisi " << s << " gateng" <
}
4-masala
X(N) i Y(N) massivlarining manfiy elementlaridanD massivini hosil qiling.D massiv elementlarini o‘sib borish tartibida joylang. 3 ta minimal elementlarni chop eting.
|
#include
using namespace std;
int main ()
{
float x[100], y[100];
int n, m;
cout<< " x[n] massivelementlarisoninikiritng : " <
cout<< " n = " << n; cin>> n;
cout<< " x[n] massivelementlarinikiriting :\n ";
for ( inti = 0; i< n; i++)
{
cout<< " x[ "<
cin>> x[i];
}
cout<< " y[n] massivelementlarinikiriting :\n ";
for ( inti = 0; i< n; i++)
{
cout<< " y[ "<
cin>> y[i];
}
float d[100];
int count = 0;
for(inti = 0; i< n; i++)
{
if(x[i] < 0)
{
d[count] = x[i];
count++;
}
}
for(inti = 0; i< n; i++)
{
if(y[i] < 0)
{
d[count] = y[i];
count++;
}
}
cout<< " d[] massivelementlari : " <
for(inti = 0; i< count; i++)
{
cout<< d[i] << " ";
}
cout<
cout<< " d[] massivelementlario'sishtartibidajoylashganholi : " <
inti, j;
int key;
for (i = 0; i< count - 1; i++)
{
for ( j = count - 1; j >i ; j--)
{
if(d[j - 1]> d[j])
{
key = d[j];
d[j] = d[j - 1];
d[j - 1] = key;
}
}
}
for(inti = 0; i< count; i++)
{
cout<< "d["<
}
cout<
cout<< " d[] massiv 3 ta massivelementlari : " <
for(inti = 0; i< 3; i++)
{
cout<< "d["<
}
cout<
}
5-masala
X=(x1,x2,…, xn) massivning juft indeksli elementlarini ketma ket tartibda Y=(y1,y2,…, yk) massivga yozing. Bunda k – juft indeksli elementlar soni. Y massivning modul bo‘yicha minimal elementini va uning indeksin toping.
|
#include
#include
using namespace std;
int main ()
{
float x[100];
int n;
cout<< " x[n] massivelementlarisoninikiritng : \n ";
cout<< " n = " << n; cin>> n;
cout<
cout<< " x[n] massivelementlarinikiriting : \n";
for ( inti = 0; i< n; i++)
{
cout<< " x[ "<
cin>> x[i];
}
cout<
float y[100];
int count = 0;
for(inti = 0; i< n; i += 2)
{
y[count] = x[i];
count++;
}
cout<< "x[n] massivnigjuftelementlaridantashkiltopgan y massiv : " <
for(inti = 0; i< count; i++)
{
cout<< y[i] << " ";
}
cout<
int min = fabs(y[0]);
for(inti = 0; i< count; i++)
{
if(min >fabs(y[i]))
{
min = fabs(y[i]);
}
}
cout<< " y massivning moduli bo'yichaengkichikelementi : " << min <
}