1 Laboratoriya ishi topshiriqlari Topshiriq №1



Download 69,44 Kb.
bet1/2
Sana31.12.2021
Hajmi69,44 Kb.
#211179
  1   2
Bog'liq
2 5210727054483393488


1 - Laboratoriya ishi topshiriqlari

Topshiriq №1
1. Ro’yxatdagi eng kichik elementini toping.

#include

#include

#include

using namespace std;

int main() {

srand(time(NULL));

int n;


cout << "Ro'yhatdagi elementlar soni: "; cin >> n;

list a;

list ::iterator min;

for (int j = 1; j <= n; j++) {

a.push_back(rand()%10-5); }

min = a.begin();

for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

if (*min > *i)

*min = *i; }

cout << "\nmin=" <<*min;

_getwch();

return 0; }

2. Ro’yxat berilgan ekrandan kirtilgan sondan qiymati katta elementlarni toping.

#include

#include

#include

using namespace std;

int main() {

srand(time(0));

int n, x;

cout << "Ro'yhat elementlari soni: "; cin >> n;

list a;

for (int j = 0; j < n; j++) {

a.push_back(rand()%50-20);

}

for (auto i = a.begin(); i != a.end(); i++) {



cout << *i << " "; }

cout << "\nSon kiriting: "; cin >> x;

for (auto i = a.begin(); i != a.end(); i++) {

if(x<*i) cout << *i << " "; }

_getwch();

return 0;}

3. Ro’yxatdagi eng katta elementini aniqlang.

#include

#include

#include

using namespace std;

int main() {

srand(time(NULL));

int n;


cout << "Ro'yhatdagi elementlar soni: "; cin >> n;

list a;

list ::iterator max;

for (int j = 1; j <= n; j++) {

a.push_back(rand() % 10 - 5); }

max = a.begin();

for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

if (*max < *i)

*max = *i; }

cout << "\nmax=" << *max;

_getwch();

return 0; }

4. Ro’yxat berilgan ekrandan kirtilgan sondan qiymati kichik elementlarni toping.

#include

#include

#include

using namespace std;

int main() {

srand(time(0));

int n, x;

cout << "Ro'yhat elementlari soni: "; cin >> n;

list a;

for (int j = 0; j < n; j++) {

a.push_back(rand() % 50 - 20);

}

for (auto i = a.begin(); i != a.end(); i++) {



cout << *i << " ";

}

cout << "\nSon kiriting: "; cin >> x;



for (auto i = a.begin(); i != a.end(); i++) {

if (x>*i)

cout << *i << " ";

}

_getwch();



return 0;

}

5. Ro’yxat berilgan ekrandan kirtilgan sonning toq qiymatdagi elementlarini ekranga chiqaring.



#include

#include

#include

using namespace std;

int main() {

srand(time(0));

int n,j=0;

cout << "Ro'yhat elementlari soni: "; cin >> n;

list a;

for (int j = 0; j < n; j++) {

a.push_back(rand() % 50 - 20);

}

for (auto i = a.begin(); i != a.end(); i++) {



cout << *i << " ";

}

cout << endl;



for (auto i = a.begin(); i != a.end(); i++) {

if( j % 2 == 0 )

cout << *i << " ";

j++;


}

_getwch();

return 0;}
6. Ro‘yxatning ikkinchi elementiga ko‘rsatkich qaytaruvchi funksiya yozing.
#include

#include

#include

using namespace std;

int main() {

srand(time(NULL));

int n, x;

cout << "Ro'yhat elementlari soni: "; cin >> n;


list a;
for (int j = 0; j < n; j++) {

a.push_back(rand() % 50 - 20);

}
for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

}

cout << endl;



auto nx = next(a.begin(), 1);

cout << *nx << '\n';


_getwch();

return 0;

}

7. Ro’yxat berilgan uning juft qiymatdagi elementlarini ekranga chiqaring.



#include

#include

#include

using namespace std;

int main() {

srand(time(0));

int n, j = 0;

cout << "Ro'yhat elementlari soni: "; cin >> n;

list a;

for (int j = 0; j < n; j++) {

a.push_back(rand() % 50 - 20);

}

for (auto i = a.begin(); i != a.end(); i++) {



cout << *i << " ";

}

cout << endl;



for (auto i = a.begin(); i != a.end(); i++) {

if (j % 2 != 0)

cout << *i << " ";

j++;


}

_getwch();

return 0;}

8.Ro‘yxatdagi oxirgi elementga ko‘rsatkich qaytaruvchi funksiya yozing.

#include

#include

#include

using namespace std;

int main() {

srand(time(NULL));

int n, x;

cout << "Ro'yhat elementlari soni: "; cin >> n;

list a;

for (int j = 0; j < n; j++) {

a.push_back(rand() % 50 - 20);

}

for (auto i = a.begin(); i != a.end(); i++) {



cout << *i << " ";

}

cout << endl;



auto nx = next(a.end(), -1);

cout << *nx << '\n';

_getwch();

return 0;}

9. Ro’yxat berilgan ekrandan kiritilgan so’zga teng bo’lgan elementi bor yo’qligini aniqlang.

#include

#include

#include


using namespace std;
int main() {

int n;


cout << "Ro'yhat elementlari soni: "; cin >> n;
list a;

string k,l;

for (int i = 1; i <= n; i++) {

cin >> k;

a.push_back(k);

}

cout << "Qidirayotgan so'z kiriting: "; cin >> l;



for (auto i = a.begin(); i != a.end(); i++) {

if (*i == l)

cout << "Bor";

}

_getwch();



return 0;

}


10. Birinchi elementni har qanday turdagi elementlari uchun ro‘yxatdan olib tashlaydigan funksiyani yozing.

#include

#include

#include


using namespace std;
int main() {

srand(time(NULL));


int n, x;
cout << "Ro'yhat elementlari soni: "; cin >> n;
list a;
for (int j = 0; j < n; j++) {

a.push_back(rand() % 50 - 20);

}
for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

}

cout << endl;



auto nx = next(a.begin(), 0);

a.remove(*nx);

for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

}

_getwch();



return 0;

}

11. Barcha ro‘yxat elementlarini ekranga chop etuvchi funksiyani yozing.



#include

#include

#include

using namespace std;

int main() {

srand(time(NULL));

int n;

cout << "Ro'yhat elementlari soni: "; cin >> n;

list a;

for (int j = 0; j < n; j++) {

a.push_back(rand() % 50 - 20); }

for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " "; }

_getwch();

return 0;}

12. Ro’yxat berilgan ekrandan kiritilgan songa teng bo’lgan elementlarni toping.

#include

#include

#include

using namespace std;

int main() {

srand(time(NULL));

int n,x;

cout << "Ro'yhat elementlari soni: "; cin >> n;

list a;

for (int j = 0; j < n; j++) {

a.push_back(rand() % 50 - 20); }

for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " "; }

cout << "\nSon kiriting: "; cin >> x;

for (auto i = a.begin(); i != a.end(); i++) {

if (x == *i)

cout << *i << " "; }

_getwch();

return 0;}

13. Ro‘yxatning nusxasini qurish, lekin teskari tartibda.

#include

#include

#include

using namespace std;

int main() {

srand(time(NULL));

int n, x;

cout << "Ro'yhat elementlari soni: "; cin >> n;

list a, b;

for (int j = 0; j < n; j++) {

a.push_back(rand() % 50 - 20);

}

cout << "Birinchi ro'yhat: ";



for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

b.push_front(*i);

}

cout << "\nIkkinchi ro'yhat: ";



for (auto i = b.begin(); i != b.end(); i++) {

cout << *i << " ";

}

_getwch();



return 0; }

14.VECTOR hosil qiling elementlarini kamayish tartibida saralang.

#include

#include

#include

#include

#include
using namespace std;

int main() {

srand(time(NULL));
int n;

cout << "Vector elementlari soni: "; cin >> n;


vector a;
for (int i = 0; i < n; i++) {

a.push_back(rand() % 50 - 20);

}

for (auto i = a.begin(); i != a.end(); i++) {



cout << *i << " ";

}

sort(a.begin(), a.end(), greater ());



cout << endl;

for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

}

_getwch();



return 0;

}

15.VECTOR hosil qiling elementlarini o’sish tartibida saralang.



#include

#include

#include

#include

#include

using namespace std;


int main() {

srand(time(NULL));


int n;

cout << "Vector elementlari soni: "; cin >> n;


vector a;
for (int i = 0; i < n; i++) {

a.push_back(rand() % 50 - 20);

}

for (auto i = a.begin(); i != a.end(); i++) {



cout << *i << " ";

}

sort(a.begin(), a.end());



cout << endl;

for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

}

_getwch();



return 0;

}

16.VECTOR elementlaridan birinchi uchragan manfiy elementini chop qiling.



#include

#include

#include
using namespace std;

int main() {

srand(time(NULL));

vector a;

int n,k=1;

cout << "Vector elementlari soni: "; cin >> n;


for (int i = 0; i < n; i++) {

a.push_back(rand() % 50 - 20);

}
for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

}

cout << endl;



for (auto i = a.begin(); i != a.end(); i++) {

if (*i < 0 && k == 1) {

cout << *i << " ";

k++; } }

_getwch();

return 0; }

17. VECTOR hosil qiling va uning tub elementlarini yig’indisini toping.

#include

#include

#include


using namespace std;
int main() {

srand(time(NULL));


vector a;

int n, k = 1, s = 0;

cout << "Vector elementlari soni: "; cin >> n;
for (int i = 0; i < n; i++) {

a.push_back(rand() % 50 );

}
for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

}

cout << endl;



for (int i = 0; i < n; i++) {

k = 1;


for (int j = 1; j <= a.at(i); j++) {

if (a.at(i) % j == 0)

k++;

}

if (k == 3) {



s += a.at(i);

}

}


cout << s;

_getwch();

return 0;}

18.VECTOR hosil qiling va uning toq qiymatdagi elementlarini yig’indisini toping

#include

#include

#include

using namespace std;

int main() {

srand(time(NULL));

vector a;

int n, k = 1, s = 0;

cout << "Vector elementlari soni: "; cin >> n;

for (int i = 0; i < n; i++) {

a.push_back(rand() % 50);

}
for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

}

cout << endl;



for (int i = 0; i < n; i++) {

if (a.at(i) % 2 != 0) {

s += a.at(i);

}

}



cout << s;

_getwch();

return 0;}

19. VECTOR hosil qiling va uning mukammal son bo’lgan i elementlarini ko’paytmasini toping.

#include

#include

#include

using namespace std;

int main() {

srand(time(NULL));

vector a;

int n, k = 1, s = 0, s1 = 1;

cout << "Vector elementlari soni: "; cin >> n;

for (int i = 0; i < n; i++) {

a.push_back(rand() % 50); }

for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " "; }

cout << endl;

for (int i = 0; i < n; i++) {

s = 0;


for (int j = 1; j < a.at(i); j++) {

if (a.at(i) % j == 0) {

s += j; } }

if (s == a.at(i)) {

cout << a.at(i) << " ";

s1 *= a.at(i); }

}

cout << endl;



cout << s1;

_getwch();

return 0;

}


20. VECTOR hosil qiling va 7 ga karrali elementlar sonini uning yig’indisiga nisbati topilsin.

#include

#include

#include


using namespace std;
int main() {

srand(time(NULL));


vector a;
int n, k = 0, s = 0;

cout << "Vector elementlari soni: "; cin >> n;


for (int i = 0; i < n; i++) {

a.push_back(rand() % 50);

}
for (auto i = a.begin(); i != a.end(); i++) {

cout << *i << " ";

}

cout << endl;


for (int i = 0; i < n; i++) {

if (a.at(i) % 7 == 0) {

s += a.at(i);

k++;


}

}

cout << float(s) / k;



_getwch();

return 0;

}


Download 69,44 Kb.

Do'stlaringiz bilan baham:
  1   2




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish