10. Vector k va m ga tеng elementlari ko`paytmasi hisoblansin


Download 0.52 Mb.
Sana30.04.2023
Hajmi0.52 Mb.
#1414736
Bog'liq
55 2-lab


1-topshiriq
10.Vector K va M ga tеng elementlari ko`paytmasi hisoblansin
#include
using namespace std;

int main() {


// vector yaratib olamiz
vector v;
//vectorga elementlar soni
int n;
cin>>n;
// vectorga elementlar qo'shib olamiz
int m;
for (int i = 0; i < n; i++) {
cin>>m;
v.push_back(m);
}
// K ni kitiramiz
int K;
cout<<"K ni kitiring ";
cin>>K;
int M;
cout<<"M ni kitiring ";
cin>>M;
int kop=1;
for (auto i =v.cbegin(); i !=v.cend(); ++i)
{
if(K==*i || M==*i)
{
kop*=*i;
}
}
cout<return 0;
}

2- topshiriq



  1. Vektorning k-inch va l-inch elementlari o’rni almashtirilsin.

#include


#include

using namespace std;


int main() {


// vector yaratib olamiz
vector v;
//vectorga elementlar soni
int n;
cin>>n;
// vectorga elementlar qo'shib olamiz
int m;
for (int i = 0; i < n; i++) {
cin>>m;
v.push_back(m);
}
// k-inch va l-inch elementlari kiritamiz
int k;
int l;
cin>>k>>l;
int temp = v[k];
v[k] = v[l];
v[l] = temp;

for (int i : v) {


std::cout << i << " ";
}
std::cout << std::endl;

return 0;


}

3-topshiriq


10.Vektor k - elementidan l - elementigacha bo`lgan elementlarining kublari yig’indisi hisoblansin

#include


using namespace std;

int main() {


// vector yaratib olamiz
vector v;
//vectorga elementlar soni
int n;
cin>>n;
// vectorga elementlar qo'shib olamiz
int m;
for (int i = 0; i < n; i++) {
cin>>m;
v.push_back(m);
}
// K ni kitiramiz
int K;
cout<<"K index ni kitiring ";
cin>>K;
int L;
cout<<"L index ni kitiring ";
cin>>L;
// k chi elementidan l elementigacha bo'lgan vectrning kublar yi'gindisini hioblash
int sum=0;
for (auto i =v.cbegin(); i !=v.cend(); ++i)
{
if(v[K-1]<=*i && v[L-1]>=*i){
sum+=pow(*i,3);
}
}
cout<}



Download 0.52 Mb.

Do'stlaringiz bilan baham:




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