O‘zbekiston Respublikasi Raqamli texnologiyalari vazirligi m uhammad al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti


Download 217.15 Kb.
Sana17.06.2023
Hajmi217.15 Kb.
#1536371
Bog'liq
BAXODIR



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
void juftSonKo'paytir(vector& massiv) {
int birinchiJuftSon = -1; // Juft sonlardan birinchi qiymat
bool juftSonMavjud = false; // Juft son mavjudligi

// 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 massiv = {1, 3, 5, 2, 6, 4, 7};

// 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;
}

TRAPETSIYA USULI

#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
#include

int main() {


std::vector stations = {'A', 'V', 'S'};
std::vector num_vagons = {80, 70, 50};
int num_points = 4;
std::vector num_vagons_per_point = {60, 45, 65, 30};
int n = 2;

// xarajatlar matritsasi


std::vector> C = {{3 + n, n - 1, 5 * n, 3},
{2 * n, 4 * n, 10, 9 + n},
{3 * n, 12 + n, n - 3, 9 + n}};

// bazis reja


std::vector> B(3, std::vector(4, 0));

// 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 vagons_for_point(i, 0);
for (int k = 0; k < i; k++) {
vagons_for_point[k] = static_cast(B[j][k]) / C[k][i];
}
// 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(min_vagons_for_point * C[i][i]));
num_vagons[j] -= B[j][i];
// bazis rejada o'zgartirish kiritamiz
for (int k = 0; k < i; k++) {
B[j][k] -= static_cast(B[j][i] * C[k][i] / C[i][i]);
}
}
}
}

// 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'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling