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.