University of management and future technologies


int countOddDivisors(int n) {


Download 45.07 Kb.
bet2/2
Sana09.10.2023
Hajmi45.07 Kb.
#1696292
1   2
Bog'liq
Ergashev Sirojddin KIDT ALGORITMLASH FANI

int countOddDivisors(int n) {
int count = 0;
for (int i = 1; i <= n; i++) {
if (n % i == 0 && i % 2 != 0) {
count++;
}
}
return count;
}


int main() {
int N;
std::cout << "Enter a number: ";
std::cin >> N;
int result = countOddDivisors(N);
std::cout << "Number of odd divisors of " << N << ": " << result << std::endl;
return 0;
}



  1. Berilgan N sonining tub bo‘luvchilari sonini topish algoritm va dasturini tuzing.



#include
#include


std::vector getPrimeDivisors(int n) {
std::vector primeDivisors;
for (int i = 2; i <= n; i++) {
if (n % i == 0) {
bool isPrime = true;
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primeDivisors.push_back(i);
}
}
}
return primeDivisors;
}


int main() {
int N;
std::cout << "Enter a number: ";
std::cin >> N;
std::vector primeDivisors = getPrimeDivisors(N);
int count = primeDivisors.size();
std::cout << "Number of prime divisors of " << N << ": " << count << std::endl;
return 0;
}

  1. Svetoforning ishlash algoritmi quyidagicha: yashil-sariq-qizil-sariq-yashil-…. Yashil va qizil ranglar 60 sekund, sariq rang 10 sekund yonib tursa, N minutdan keyin svetoforning qaysi rangi yonishini aniqlash algoritmi va dasturini tuzing.

#include


std::string getTrafficLightColor(int minutes) {


int seconds = minutes * 60;
int cycleTime = 60 + 10 + 60;
int completeCycles = seconds / cycleTime;
int remainingSeconds = seconds % cycleTime;

if (remainingSeconds < 60) {


return "Green";
} else if (remainingSeconds < 70) {
return "Yellow";
} else if (remainingSeconds < 130) {
return "Red";
} else {
return "Yellow";
}
}

int main() {


int N;
std::cout << "Enter the number of minutes: ";
std::cin >> N;
std::string color = getTrafficLightColor(N);
std::cout << "After " << N << " minutes, the traffic light will be " << color << std::endl;
return 0;
}



  1. Svetoforning ishlash algoritmi quyidagicha: yashil-sariq-qizil-sariq-yashil-…. Yashil va qizil ranglar 60 sekund, sariq rang 10 sekund yonib tursa, N minutdan keyin svetoforning yashil rangi necha marta yonishini aniqlash algoritmi va dasturini tuzing.

#include

int main() {


int totalTime = 0;
int greenCount = 0;
int N;

std::cout << "Enter the number of minutes: ";


std::cin >> N;

totalTime = N * 60;


greenCount = totalTime / 70;

std::cout << "The traffic light will turn green " << greenCount << " times after " << N << " minutes." << std::endl;


return 0;


}
11. Quyidagi shartlardan birini bajaradigan yil kabisa yili hisoblanadi: Yil raqami 400 ga bo‘linsa, Yil raqami 4 ga bo‘linsa va 100 ga bo‘linmasa. Kiritilgan yil raqami “Kabisa yili” ekanligini aniqlash algoritm va dasturini tuzing.

#include


int main() {


int year;

std::cout << "Enter the year: ";


std::cin >> year;

if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {


std::cout << year << " is a leap year." << std::endl;
} else {
std::cout << year << " is not a leap year." << std::endl;
}

return 0;


}


Toshkent - 2023

Download 45.07 Kb.

Do'stlaringiz bilan baham:
1   2




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