4. Vector ni ga va ga bo`linadigan elementlarini ko`paytmasini sinusi tоpilsin


Download 0.52 Mb.
Sana30.04.2023
Hajmi0.52 Mb.
#1417475
Bog'liq
44 2-lab


1-topshiriq
14.Vector ni 2 ga va 5 ga bo`linadigan elementlarini ko`paytmasini sinusi tоpilsin

#include


#include
#include

int main() {


std::vector v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
double result = 1.0;

for(int i = 0; i < v.size(); i++) {


if(v[i] % 2 == 0 && v[i] % 5 == 0) {
result *= v[i];
}
}

std::cout << "Result: " << sin(result)<< std::endl;


return 0;
}

2-topshiriq
8. a Vektorning k-elementidan boshlab b Vektor qo’shilib yangi с Vektor hosil qilinsin.

#include


#include

using namespace std;

int main() {
vector kVector = {1, 2, 3, 4, 5}; // K vektoriga qiymatlar kiritildi
vector bVector = {6, 7, 8}; // B vektoriga qiymatlar kiritildi
vector cVector; // C bo'sh vektori yaratildi
int k=3;
// B vektorini C vektoriga qo'shib chiqamiz
for(int i = 0; i < bVector.size(); i++) {
cVector.push_back(bVector[i]);
}
// K vektorini C vektoriga qo'shib chiqamiz
for(int i = 0; i < kVector.size(); i++) {
if(i>=k)
cVector.push_back(kVector[i]);
}
// C vektorining barcha qiymatlarini ekranga chiqaramiz
for(int i = 0; i < cVector.size(); i++) {
cout << cVector[i] << " ";
}
return 0;
}

3-topshiriq
14. Vektorni juft qiymatli elementlarini o`rtacha qiymatidan hisoblansin

#include

using namespace std;

int main()


{
int n = 10;
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

int sum = 0;


int count = 0;

for(int i = 0; i < n; i++)


{
if(a[i] % 2 == 0) // juft sonlarni aniqlab olish
{
sum += a[i]; // yig'indini hisoblash
count++; // nechta son hisoblandigini saqlash
}
}

if(count > 0)


{
float avg = (float)sum / count; // o'rta arifmetikni hisoblash
cout << "Juft sonlar o'rtacha qiymati: " << avg << endl;
}
else
{
cout << "Massivda juft sonlar yo'q." << endl;
}

return 0;


}

Download 0.52 Mb.

Do'stlaringiz bilan baham:




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