6-amaliy ish Bajardi: Erkinov Oybek Tekshirdi: Shokirov Shodmon Toshkent 2023


Download 78.87 Kb.
Sana17.06.2023
Hajmi78.87 Kb.
#1536272
Bog'liq
Dasturlash 2 6-amaliy ish


O‘ZBEKISTON RESPUBLIKASI AXBOROT
TEXNOLOGIYALARI VA
KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI

Dasturlash 2 fanidan
6-amaliy ish



Bajardi: Erkinov Oybek


Tekshirdi: Shokirov Shodmon


Toshkent 2023.
6 - LABORATORIYA ISHI
Variant raqami - 7.
a) Valarray sinfidan funksiyalaridan foydalanib, to’plamning juft
elementlarini yig’indisini hisoblang.

Dastur Kodi:
#include
#include
#include
#include
#include
using namespace std;
int juft(int son)
{
return son % 2 == 0 ? son : 0;
}
int main()
{
srand(time(NULL));
int nechta;
cout << "\n \"valarray\" massivining elementlari sonini kiriting: ";
cin >> nechta;
valarray<int> v_arr1(nechta);
int in = 0;
cout << "\n Massivning dastlabki elementlari:\n " << endl;
while (in < nechta)
{
v_arr1[in] = rand() % 60 + 1;
cout << setw(3) << in + 1 << ".| " << setw(4) << v_arr1[in++] << endl;
}
valarray<int> v_arr2_juft = v_arr1.apply(juft);
cout << "\n Massivning juft qiymatdagi elementlari:\n " << endl;
in = 0;
for (auto it = begin(v_arr2_juft); it != end(v_arr2_juft); it++)
{
in++;
if (*it != 0)
cout << "|" << setw(2) << in << ".| " << setw(4) << *it << endl;
}
int juft_sum = v_arr2_juft.sum();
cout << "\n Va bu elementlarning yig'indisi -> " << juft_sum << endl;
cout << endl;
system("pause");
return 0;
}


Dastur Natijasi:


a)Slice sinfidan foydalanib valarray massiv elementlari har 4


qadamdagilarni aniqlang.


Dastur Kodi:
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int size;
cout << "\n valarray massivining elementlari sonin kiriting: ";
cin >> size;
valarray<int> ar(size);
cout << "\n massivning dastlabki elementlaari:\n " << endl;
for (int i = 0; i < size; i++)
{
ar[i] = rand() % 99 + 10; // 10 -> 108
cout << "[|] " << setw(2) << i << ": " << setw(4) << ar[i] << endl;
}
valarray<int> ar4_qadam = ar[slice(0, ((size + 2) / 4 ), 4)];
cout << "\n Massivning har 4 qadamdagi elementlaari:\n " << endl;
for (int i = 0; i < ar4_qadam.size(); i++)
{
cout << "|.| " << setw(2) << i * 4 << ": " << setw(4) << ar4_qadam[i] << endl;
}
cout << endl;
system("pause");
return 0;
}


Dastur Natijasi:


Download 78.87 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling