O‘zbekiston Respublikasi Raqamli texnologiyalari vazirligi m uhammad al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti
Download 217.15 Kb.
|
BAXODIR
- Bu sahifa navigatsiya:
- Toshkent-2023
O‘zbekiston Respublikasi Raqamli texnologiyalari vazirligi M uhammad al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti Algoritmlarni loyihalash Amaliy ishi Guruh : 716-21 Bajardi: Abduqahhorov Baxodir Tekshirdi: Ravshanov Anvar Toshkent-2023 2-VARIANT 1-ISH N o`lchamli butun tipli massiv berilgan. Birinchi juft sonning dastlabki qiymati massivdagi barcha juft sonlarga ko`paytirilsin. Agar massivda juft son bo`lmasa, massiv o`zgartirishsiz qoldirilsin. #include #include using namespace std; // Massivni birinchi juft sonning qiymatini barcha juft sonlarga ko'paytirish
// Massivdagi birinchi juft sonni izlash for (int i = 0; i < massiv.size(); i++) { if (massiv[i] % 2 == 0) { birinchiJuftSon = massiv[i]; juftSonMavjud = true; break; } } // Massivdagi barcha juft sonlarni ko'paytirish if (juftSonMavjud) { for (int i = 0; i < massiv.size(); i++) { if (massiv[i] % 2 == 0) { massiv[i] *= birinchiJuftSon; } } } } int main() { // Massivni yaratish vector // Juft sonlarni ko'paytirish juftSonKo'paytir(massiv); // Natijani chiqarish cout << "Natija: "; for (int i = 0; i < massiv.size(); i++) { cout << massiv[i] << " "; } cout << endl; return 0; } Natijada massivning o’zgaruvchilari 1 3 5 4 12 8 7 bo’ladi. 2-ish 1) tg(0.58x+0.1)=x2 2) x3 -6x-8=0 1) #include #include double f(double x) { return tan(0.58 * x + 0.1) - x * x; } double df(double x) { double sec2x = 1 / (cos(0.58 * x + 0.1) * cos(0.58 * x + 0.1)); return 0.58 * sec2x - 2 * x; } double findRoot(double x0, double epsilon) { double x = x0; double y = f(x); double dy_dx = df(x); while (fabs(y) > epsilon) { x = x - y / dy_dx; y = f(x); dy_dx = df(x); } return x; } int main() { double x0 = 1.0; // boshlang'ich taxminiy qiymat double epsilon = 0.001; // xatolik epsilon qiymati double root = findRoot(x0, epsilon); std::cout << "Funksiyaning ildizi: " << root << std::endl; return 0; } 2) #include #include double f(double x) { return x * x * x - 6 * x - 8; } double df(double x) { return 3 * x * x - 6; } double findRoot(double x0, double epsilon) { double x = x0; double y = f(x); double dy_dx = df(x); while (fabs(y) > epsilon) { x = x - y / dy_dx; y = f(x); dy_dx = df(x); } return x; } int main() { double x0 = 1.0; // boshlang'ich taxminiy qiymat double epsilon = 0.001; // xatolik epsilon qiymati double root = findRoot(x0, epsilon); std::cout << "Funksiyaning ildizi: " << root << std::endl; return 0; } 3-ISH TO’RTBURCHAKLAR USULI #include #include double f(double x) { return (pow(tan(x),2)+pow(1/tan(x),2)); } int main() { double a = M_PI/6; // Boshlang'ich qiymat double b = M_PI/3; // Tugallanish qiymati double n = 10000.0; // Bo'limlar soni double h = (b - a) / n; // Bo'limlar kengligi double integral = 0.0; // To'rtburchak usulidan foydalanib integralni hisoblash for (double i = a; i < b; i += h) { double f1 = f(i); double f2 = f(i + h); integral += (f1 + f2) / 2.0 * h; } std::cout << "Integralning qiymati: " << integral << std::endl; return 0;
#include #include double f(double x) { return (pow(tan(x),2)+pow(1/tan(x),2)); } int main() { double a = M_PI/6; // Kesmalar orasidagi boshlang'ich qiymat double b = M_PI/3; // Kesmalar orasidagi oxirgi qiymat int n = 4, m = n / 2; // Kesmalar soni double h = (b - a) / n; // Kesmalar uzunligi double integral = 0.0; for (int i = 1; i < m; i++) { integral += f(a + (2 * i - 2) * h) + 4 * f(a + (2 * i - 1) * h) + f(a + 2 * i * h); } integral = integral * h / 3; // Javobni hisoblaymiz std::cout << "Integralning qiymati: " << std::fixed << integral << std::endl; return 0; } 4-ISH
#include #include int main() { std::vector std::vector int num_points = 4; std::vector int n = 2; std::vector {2 * n, 4 * n, 10, 9 + n}, {3 * n, 12 + n, n - 3, 9 + n}}; // bazis reja std::vector // bazis rejayi tayyorlash for (int i = 0; i < num_points; i++) { for (int j = 0; j < 3; j++) { // birinchi punktga vagonlar to'plamini jo'natamiz if (i == 0) { B[j][i] = std::min(num_vagons[j], num_vagons_per_point[i]); num_vagons[j] -= B[j][i]; } else { // j-ta stantsiyadagi vagondan qancha punktga jo'natilishi kerakligini topamiz std::vector for (int k = 0; k < i; k++) { vagons_for_point[k] = static_cast } // j-ta stantsiyadagi vagondan eng kam necha punktga jo'natilishi kerakligini topamiz double min_vagons_for_point = *std::min_element(vagons_for_point.begin(), vagons_for_point.end()); // j-ta stantsiyadagi vagondan eng kam necha ta punktga jo'natishni rejalashtiramiz B[j][i] = std::min(num_vagons[j], static_cast num_vagons[j] -= B[j][i]; // bazis rejada o'zgartirish kiritamiz for (int k = 0; k < i; k++) { B[j][k] -= static_cast } } } } // Bazis rejaning natijasini chiqaramiz std::cout << "Bazis reja:" << std::endl; for (const auto& row : B) { for (const auto& val : row) { std::cout << val << " "; } std::cout << std::endl; } return 0; } Download 217.15 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling