I-bosqich ki-12-22 guruh talabasi shavkatov sirojbek ning “dasturlash2


Download 340.29 Kb.
bet4/11
Sana18.06.2023
Hajmi340.29 Kb.
#1564702
1   2   3   4   5   6   7   8   9   10   11
Bog'liq
O-3XWxhqJ4kseNw9IGwHXz8oEzECnwoh

5. Shift (): —Ushbu funksiya elementlarni argument sifatida ko'rsatilgan raqamga o'tkazgandan so'ng, yangi valarray ni qaytaradi. Agar raqam musbat bo'lsa, chap siljish qo'llaniladi, agar salbiy bo'lsa, o'ng tomonga siljish qo'llaniladi.
6. CSHIFT (): — Ushbu funktsiya argument sifatida ko'rsatilgan raqam bo'yicha elementlarni aylantirgan (aylantirgan) dan keyin yangi valarrayni qaytaradi. Agar raqam musbat bo'lsa, chap siljish va aylana qo'llaniladi, agar son salbiy bo'lsa, chap siljish qo'llaniladi.




Выход:
The new valarray after shifting is : 20 1 30 0 0
The new valarray after circular shifting is : 20 1 30 10 2
7. swap () : — Bu funksiya bir valarray ni boshqasiga o’zgartiradi.

// C ++ da swap() ni ishlatish uchun masala
#include
#include // for valarray functions
using namespace std;
int main()
{
// 1- valarray ishga tushushi
valarray varr1 = {1, 2, 3, 4};

// 2- valarray ishga tushushi


valarray varr2 = {2, 4, 6, 8};

// O’zgarishdan oldingi qiymatlarni ko’rish


cout << "The contents of 1st valarray "
"before swapping are : ";
for (int &x : varr1)
cout << x << " ";
cout << endl;
cout << x << " ";

cout << "The contents of 2nd valarray "


"before swapping are : ";
for (int &x : varr2)
cout << endl;

//Qiymatlarni almashtirish uchun swap () dan foydalanish


varr1.swap(varr2);

// Qiymatlarni almashishdan keying holati


cout << "The contents of 1st valarray "
"after swapping are : ";
for (int &x : varr1)
cout << x << " ";
cout << endl;

cout << "The contents of 2nd valarray "


"after swapping are : ";
for (int &x : varr2)
cout << x << " ";
cout << endl;

return 0;

}


Выход:
The contents of 1st valarray before swapping are : 1 2 3 4
The contents of 2nd valarray before swapping are : 2 4 6 8
The contents of 1st valarray after swapping are : 2 4 6 8
The contents of 2nd valarray after swapping are : 1 2 3 4



Download 340.29 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10   11




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