|
Komputer injiniring
|
Sana | 02.01.2024 | Hajmi | 314,95 Kb. | | #129470 |
Bog'liq dasturlash
O’ZBEKISTON RESPUBLIKASI RAQAMLI TEXNOLOGIYALAR
VA KAMUNIKATSIYALARNI RIVOJLANRITISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
“KOMPUTER INJINIRING ”yo’nalishi
023-22 GURUH TALABASI
SOTIVOLDIYEV SUHROBJON
1-AMALIY MASHG’ULOTI
Bajardi: Sotivoldiyev Suhrobjon
O’qituvchi: Fayzullayeva Z
1-masala Takrorlanuvchi
x haqiqiy va n butun sonlari berilgan(n>0). 1+x+(sqrt(x,2)/2!)+...+sqrt(x,n)/n! ifodaning qiymati hisoblansin
#include
#include
#include
double calculateSeries(int x, int n) {
double result = 1.0;
double factorial = 1.0;
for (int i = 1; i <= n; ++i) {
factorial *= i;
result += sqrt(x) / factorial;
}
return result;
}
int main() {
// x va n ni olish
int x, n;
std::cout << "x va n ni kiriting (n>0): ";
std::cin >> x >> n;
// Qiymatni hisoblash va ekranga chiqarish
double seriesResult = calculateSeries(x, n);
std::cout << std::setprecision(10) << "Qiymat: " << seriesResult << std::endl;
return 0;
}
2-masala Tarmoqlanuvchi
uch xonali son berilgan. Uning raqamlari o'suvchi yoki kamayuvchi ketma-ketlik tashkil etishi tekshirilsin
#include
bool isConsecutiveIncreasingOrDecreasing(int number) {
int digit1 = number % 10;
number /= 10;
int digit2 = number % 10;
number /= 10;
int digit3 = number % 10;
// O'sish yoki kamayishni tekshirish
bool increasing = (digit1 > digit2) && (digit2 > digit3);
bool decreasing = (digit1 < digit2) && (digit2 < digit3);
// Natijani qaytarish
return increasing || decreasing;
}
int main() {
// Uch xonali sonni olish
int userInput;
std::cout << "Uch xonali sonni kiriting: ";
std::cin >> userInput;
// Qiymatni hisoblash va ekranga chiqarish
bool result = isConsecutiveIncreasingOrDecreasing(userInput);
// Natija ekranga chiqarish
std::cout << std::boolalpha << result << std::endl;
return 0;
}
3-masala massiv
N o`lchamli massiv hamda K va L butun sonlari berilgan. (1≤K≤L≤N). K-nomerdan L-nomergacha bo`lgan elementlardan boshqa barcha massiv elementlarining yig`idisi topilsin.
#include
int main() {
int N;
std::cout << "Massiv o'lchamini kiriting: ";
std::cin >> N;
int K, L;
std::cout << "K ni kiriting (1<=K<=L<=N): "; std::cin >> K;
std::cout << " L ni kiriting (1<=K<=L<=N): "; std::cin >> L;
int* array = new int[N];
for (int i = 0; i < N; ++i) {
std::cout <> array[i];
}
int sum =0;
for(int i=0;isum+=array[i];
}
for(int j = K;j<=L;j++) sum+=array[j];
std::cout << "Yig'indi: " << sum << std::endl;
return 0;
}
4-masala while
N butun soni berilgan (n>1). N sonini tub yoki tub emasligini aniqlovchi dastur tuzilsin
#include
bool isPrime(int n) {
if (n <= 1) {
return false; // 1 va undan kichik sonlar tub emas
}
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) {
return false; // Tub son emas
}
}
return true; // Tub son
}
int main() {
// Foydalanuvchidan butun sonni olish
int n;
std::cout << "Butun son kiriting (n>1): ";
std::cin >> n;
// Tub sonligini tekshirish va natijani ekranga chiqarish
if (isPrime(n)) {
std::cout << n << " - Tub son.\n";
} else {
std::cout << n << " - Tub emas son.\n";
}
return 0;
}
|
| |