Мustaqil ta’lim ish hisoboti Fan “ Algoritmlarni loyihalash” Guruh ki-2102 Talaba


-topshiriq Butun sonlardan iborat NxM o’lchamli matritsa berilgan. Bu matritsani gorizontalga nisbatan ko’chirilgan holatda chiqaring


Download 470.6 Kb.
bet7/7
Sana19.06.2023
Hajmi470.6 Kb.
#1605458
1   2   3   4   5   6   7
Bog'liq
Algoritmlarni loyihalash fanidan 1-mustaqil ishi Baxromov Ozodbek

2-topshiriq
Butun sonlardan iborat NxM o’lchamli matritsa berilgan. Bu matritsani gorizontalga nisbatan ko’chirilgan holatda chiqaring

3 4
5 9 2 6
6 2 4 3
1 2 8 7

1 2 8 7
6 2 4 3
5 9 2 6

Berilgan misol C++ tilidagi kodlari:
#include
#include
using namespace std;

int main() {


int n,m;
cin>>n>>m;
int matrix[n][m];

// Matritsani kiritish


for(int i=0; ifor(int j=0; jcin >> matrix[i][j];
}
}

// Matritsaning gorizontal holatda chiqarish


for(int i=0; ifor(int j=m-1; j>=0; j--) {
cout << matrix[i][j] << " ";
}
cout << endl; // Har bir satrni yakunida yangi qatordan chiqish
}

return 0;


}
Natijasi(kompilyatsiya jarayoni)


2-Amaliy mashg’ulot topshiriqlari
2-amaliy mashg‘uloti mavzusi: Massiv elementlarini tartiblashtirish. Matrisa maksimal, minimal elementnlarini aniqlash algoritmi
1-topshiriq
[2 3 1 5]
[4 5 8 7]
[0 6 -7 2]
[1 6 4 9]
Kvadrat matritsani asosiy diоganal elеmеntlaridan eng kattasi va yordamchi dioganal elementlaridan eng kichigi tоpilsin
Berilgan masala C++ kodlari
#include
#include
using namespace std;

int main() {


int matrix[4][4] = {{2,3,1,5},{4,5,8,7},{0,6,-7,2},{1,6,4,9}};


int maxDiagElem = matrix[0][0];
int minDiagElem = matrix[0][3];

for(int i=0; i<4; i++){


if(matrix[i][i] > maxDiagElem){
maxDiagElem = matrix[i][i];
}
if(matrix[i][3-i] < minDiagElem){
minDiagElem = matrix[i][3-i];
}
}

cout<<"Eng katta diagonal element: "<
cout<<"Eng kichik yordamchi diagonal element: "<

return 0;


}
Berilgan dastur natijasi(kompilyatsiya jarayoni)


2-topshiriq
Quyidagi funksiyani to’rtburchaklar, Trapetsiya formulalari yordamida taqribiy hisoblash dasturini tuzing
Berilgan maslamimg C++ tilidagi kodlari: Trapetdiyalar formulasi asosida
#include
#include
#include

using namespace std;

double f(double x) {
return x*x*x*x*x * cos(3*x);
}

int main() {


double a = -3, b = 3;
int n = 1000; // number of subintervals
double h = (b - a) / n;

double integral = 0.5 * (f(a) + f(b)); // initial value for integral


for (int i = 1; i < n; i++) {
double x = a + i*h;
integral += f(x);
}

integral *= h;

cout << "The approximate value of the integral is: " << integral << endl;

return 0;


}
Berilgan masalaning Dastur natijasi (kompilyatsiya jarayoni)


Berilgan maslamimg C++ tilidagi kodlari:To’rtburchaklar formulasi yordamida
#include
#include
#include

using namespace std;


double f(double x) {
return pow(x, 5) * cos(3*x);
}

double trapezoidalIntegration(double a, double b, int n) {


double h = (b - a) / n;
double integral = 0;
for (int i = 0; i <= n; i++) {
double x = a + i * h;
if (i == 0 || i == n) {
integral += f(x) / 2;
} else {
integral += f(x);
}
}
integral *= h;
return integral;
}

int main() {


double a = -3;
double b = 3;
int n = 1000;
double result = trapezoidalIntegration(a, b, n);
cout << "Integral value: " << result << endl;
return 0;
}
Berilgan masalaning Dastur natijasi (kompilyatsiya jarayoni)


Xulosa:
Meni Xulosam shundan iboratki men bu Mustaqil ta’lim vazifasidan Matritsalarni maksimal va minimal elementlarini topishni organib bubi ham amalda bajara oladigan bo’ldim. Matritsani gorizontga nisbatan almashtirish amalini ham o’rganib oldim. Kvadrat matritsani asosiy diоganal elеmеntlaridan eng kattasi va yordamchi dioganal elementlaridan eng kichigi tоpish dasturini tushizni ham mustaqil tarzda organib chiqib natija ola oldim. Sonlarning juft bo'luvchilari sonini topish algoritmni va dasturini tuzishni mustaqil tarzda o’rganib chiqdim va amalda bajardim.

Download 470.6 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7




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