13. Vector manfiy elementlarini o`rtacha qiymatidan hisoblansin
Download 0.65 Mb.
|
13 2-lab
1-topshiriq 13. Vector manfiy elementlarini o`rtacha qiymatidan hisoblansin #include using namespace std; int main() { // vector yaratib olamiz vector //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); } //manfiy elementlar o'rtacha qiymati int sum=0,soni; for (auto i =v.cbegin(); i !=v.cend(); ++i) { if(*i<0) { sum+=*i; soni++; } } cout<<"Javob "< } 2-topshiriq 1. Vektorning eng katta va eng kichik elementlari o’rni almashtirilsin. #include using namespace std; int main() { // vector yaratib olamiz vector //vectorga elementlar soni int n; cin>>n; // vectorga elementlar qo'shib olamiz int m; for (int i = 0; i < n; i++) { cin>>m; myVector.push_back(m); } int min = 0; for (int i = 0; i < myVector.size(); i++) if (myVector[i] < myVector[min]) min = i; int max =0; for (int i = 0; i < myVector.size(); i++) if (myVector[i] > myVector[max]) max = i; swap(myVector[min],myVector[max]); cout<<"Vector elementlari = "; for(int i=0;i cout< cout< int main() { std::transform(v.begin(), v.end(), v.begin(), [min_elem](int elem) { // Kvadratiga oshirish for (int elem : v) { return 0; Download 0.65 Mb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling