1-amaliyot ishi
Download 28.29 Kb.
|
Asad dasturlash 2
2-amaliyot ishi.
1-topshiriq Vector M dan kata elementlarini ko`paytmalarini logarifmi hisoblansin. #include #include #include using namespace std; int main() {
for (int i = 0; i < M.size(); i++) { double value = log10(M[i]); result.push_back(value); } cout << "M: "; for (double element : M) { cout << element << " "; } cout << endl << "Result: "; for (double element : result) { cout << element << " "; } cout << endl; return 0;
Bu kodda, vector 2-topshiriq a Vektorning juft qiymatli elementlarini b Vektorga, toq qiymatli elementlarini с Vektorga joylashtiring. #include #include using namespace std; int main() {
for (int i = 0; i < a.size(); i++) { if (a[i] % 2 == 0) { b.push_back(a[i]); } else { c.push_back(a[i]); } } cout << "a: "; for (int element : a) { cout << element << " "; } cout << endl << "b: "; for (int element : b) { cout << element << " "; } cout << endl << "c: "; for (int element : c) { cout << element << " "; } cout << endl; return 0;
#include #include #include using namespace std; int main() { vector int k = 2; auto it = max_element(a.begin(), a.end()); int max_element_index = distance(a.begin(), it); if (max_element_index >= k) { swap(a[max_element_index], a[k]); } cout << "a: "; for (int element : a) { cout << element << " "; } cout << endl; return 0; } Bu kodda, vector Download 28.29 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling