1.Vector elementlarini o`rtacha qiymati hisoblansin.
#include #include
#include using namespace std;
int main()
{ vector v = { 10, 20, 30, 40, 50 };
int sum = accumulate(v.begin(), v.end(), 0);
float ortacha = static_cast(sum) / v.size(); cout << "O'rta qiymat: " << ortacha << endl; return 0;}
|
2.Vector [a,b] qismidagi elementlari yig'indisini topadi:
#include #include
#include
using namespace std; int main()
{vector v = { 10, 20, 30, 40, 50, 60, 70, 80, 90 }; int a = 2, b = 6;
int sum = accumulate(v.begin() + a, v.begin() + b + 1, 0); cout << "Vector [" << a << "," << b << "] elementlari yig'indisi: " << sum << endl; return 0;}
|
3.Vector k – elementidan l – elementigacha bo`lgan elementlarining o`rtacha qiymati hisoblansin.#include
#include #include
using namespace std; int main(){
vector v = { 10, 20, 30, 40, 50, 60, 70, 80, 90 };
int k = 2, l = 6; vector::iterator start = v.begin() + k;
vector::iterator end = v.begin() + l + 1;
int sum = accumulate(start, end, 0);
float ortacha= static_cast(sum) / (l - k + 1);
cout << "Vector [" << k << "," << l << "] elementlari o'rta qiymati: " << ortacha << endl; return 0;}
|
4.Vectorni min elementi Vectorni oxirgi elementi bilan o`rin almashtirilsin
#include #include
#include using namespace std;
int main(){ vector v = { 10, 20, 30, 40, 5, 60, 70, 80, 90 };
vector::iterator min_it = min_element(v.begin(), v.end());
int min_val = *min_it;
int last_val = v.back();
*min_it = last_val;
v.pop_back();
v.push_back(min_val);
cout << "Yangi vector: "; for (auto i : v)
cout << i << " "; cout << endl;
return 0; }
|
5.Vector [a,b] qismda yotmaydigan elementlarining o`rtacha qiymatidan hisoblansin
#include #include
#include
using namespace std; int main() {
vector v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int a = 2, b = 7; int sum = 0, son= 0;
for(int i = 0; i < v.size(); i++) {
if(i < a || i > b) { sum += v[i]; son++;
} } double ortacha= (double) sum / son;
cout << "Ortacha qiymat: " << ortacha << endl;
return 0;}
|
6.Vector elementlarini kvadratlarini yig‘indisi hisoblansin
#include
#include
#include
using namespace std;
int main() {
vector v = {1, 2, 3, 4, 5}
int sum = 0;
for(int i = 0; i < v.size(); i++)
{ sum += v[i] * v[i]; }
cout << "Vector el/ning kvad/yig'indisi: " << sum << endl;
return 0;}
|
7.Vectorni barcha elementlari Vectorni eng katta elementiga bo`lib chiqilsin#include
#include
#include
using namespace std;
int main() {
vector v = {5, 3, 8, 2, 9, 1};
double maxElement = *max_element(v.begin(), v.end()); // eng katta elementni topish
for(float i = 0; i < v.size(); i++) {
cout << v[i] / maxElement << " "; // har bir elementni eng katta elementga bo'lib chiqish
} cout << endl;
return 0;}
|
8.Vectorni barcha elementlari Vectorni eng kichik elementiga bo`lib chiqilsin
#include #include
#include
using namespace std;
int main() {
vector v = {5, 3, 8, 2, 9, 1};
float minElement = *min_element(v.begin(), v.end()); // eng kichik elementni topish
for(double i = 0; i < v.size(); i++) {
cout << v[i] / minElement << " "; // har bir elementni eng kichik elementga bo'lib chiqish }
cout << endl; return 0;}
|
9.Vector M dan kata elementlarini ko`paytmalarini logarifmi hisoblansin
#include #include
#include using namespace std;
int main() {
vector v = {2, 4, 6, 8, 10};
int M = 5; // katta qiymat. double sum = 0;
for(int i = 0; i < v.size(); i++) {
if(v[i] > M) { // M dan kata elementlarni topish
sum += log10(v[i] / M); // logarifm hisoblash va yig'indiga qo'shish } }
cout << "Ko'paytmalarining logarifmi: " << sum << endl;
return 0;}
|
10.Vector K yoki M ga tеng elementlari ko`paytmasi hisoblansin #include
#include #include
using namespace std; int main() {
vector v = {2, 4, 5, 7, 5, 2};
int K = 5; // K ga teng elementlarni topish
int M = 3; // M ga teng elementlarni topish
int natija = 1;
for(int i = 0; i < v.size(); i++) {
if(v[i] == K || v[i] == M) { // K yoki M ga teng elementlarni topish
natija*= v[i]; // ko'paytmani hisoblash } }
cout << "Ko'paytma: " << natija<< endl; return 0;}
|
|
|
Do'stlaringiz bilan baham: |