Guruh: ki-s22-06 Bajardi




Download 1,33 Mb.
bet2/2
Sana22.12.2023
Hajmi1,33 Mb.
#126808
1   2
Bog'liq
Amaliy ish-4

Amaliy ish
Sizga n natural soni berilgan. Sizning vazifangiz uning natural bo’luvchilarining sonini topishdan iborat.

Dastur kodi:


#include

int main() {


int n;
std::cout << "Enter a natural number (1<=n<=105): ";
std::cin >> n;

int count = 0;


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


if (n % i == 0) {
count++;
}
}

std::cout << "Number of natural divisors of " << n << " is: " << count << std::endl;


return 0;


}

Natija:
(Piramida) Foydalanuvchi tomonidan butun son kiritilganda 1 dan 15 gacha, mazkur sonlar yordamida piramida shaklini chop etuvchi dastur kodini yozing.

Dastur kodi:


#include

int main() {


int n;
std::cout << "Enter a positive integer (1 <= n <= 15): ";
std::cin >> n;

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


// Spaces before numbers
for (int j = 0; j < n - i; j++) {
std::cout << " ";
}

// Decreasing part of the pyramid


for (int j = i; j >= 1; j--) {
std::cout << j << " ";
}

// Increasing part of the pyramid


for (int j = 2; j <= i; j++) {
std::cout << j << " ";
}

std::cout << std::endl;


}

return 0;


}

Natija:

“Sonni top” o`yini. Kompyuter 0 va 10 oralig`ida bitta son o`ylasin. Foydalanuvchini son kiritishga undaydi va qachonki, foydalanuvchi kompyuter o`ylagan sonni kiritmagunicha bu jarayon davom etadi.


Dastur kodi:


#include
#include
#include

int main() {


// Set seed for random number generation
std::srand(std::time(0));

// Generate a random number between 0 and 10


int computerNumber = std::rand() % 11;

std::cout << "Kompyuter 0 va 10 oralig'ida bir son o'yladi. "


"Siz ham o'ylagan sonni kiriting." << std::endl;

int userGuess;


do {
std::cout << "Sizning o'ylagan soningizni kiriting: ";
std::cin >> userGuess;

if (userGuess < computerNumber) {


std::cout << "Sizning soningiz kompyuter o'ylagan sondan kichik. Yana urunib ko'ring." << std::endl;
} else if (userGuess > computerNumber) {
std::cout << "Sizning soningiz kompyuter o'ylagan sondan katta. Yana urunib ko'ring." << std::endl;
} else {
std::cout << "Tabriklaymiz! Siz kompyuter o'ylagan sonni topdingiz: " << computerNumber << std::endl;
}
} while (userGuess != computerNumber);

return 0;


}
Natija:

Ikkita butun sonning eng katta umumiy bo’luvchisini hisoblaydigan dastur tuzing. Quyida dastur bajarilishi vaqtida taklif etiladigan ekran ko’rinishi keltirilgan (foydalanuvchi kiritgan ma’lumotlar yarim qalin shriftda berilgan).


Dastur kodi:


#include

// Funktsiyani e'lon qilish


int EKUB(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}

int main() {


// Sonlarni olish
int num1, num2;
std::cout << "Sonlarni kiriting: ";
std::cin >> num1 >> num2;

// EKUB ni hisoblash va natijani chiqarish


int ekubResult = EKUB(num1, num2);
std::cout << "EKUB(" << num1 << ", " << num2 << ") = " << ekubResult << std::endl;

return 0;


}
Natija:

Foydalanuvchi kiritgan o'nlik sonni ikkilikka o'tkazadigan dastur tuzing. Quyidagi dastur bajarilishi vaqtida taklif etiladigan ekran ko'rinishi keltirilgan.


Dastur kodi:


#include
#include

int main() {


int onlikSon;
std::cout << "O'nlik sonni kiriting: ";
std::cin >> onlikSon;
std::bitset<8> ikkilikSon(onlikSon);
std::cout << "O'nlikdagi " << onlikSon << " sonining mos ikkilikdagi tasviri " << ikkilikSon << std::endl;

return 0;


}

Natija:



Download 1,33 Mb.
1   2




Download 1,33 Mb.