N o`lchamli a massiv berilgan. Uning toq nomerli elementlari ichidan eng kattasi topilsin


Download 30.53 Kb.
Sana13.05.2023
Hajmi30.53 Kb.
#1456169
Bog'liq
Algoritm 1-amaliy


  1. N o`lchamli A massiv berilgan. Uning toq nomerli elementlari ichidan eng kattasi topilsin.

#include


using namespace std;

int main() {


int n, max_num = 0,x;
cout<<"Massiv uzunligini kiriting:";
cin >> n;
for (int i = 1; i <= n; i++) {
cout<cin >> x;
if (x % 2 == 1 && x > max_num) {
max_num = x;
}
}
cout <<"Max= " <return 0;
}



  1. Aniqlangan oraliqda ildizning taqribiy qiymatini 0.001 aniqlikda hisoblang. Kesmani teng ikkiga bo‘lish usuli bilan taqribiy hisoblang.

2.1 x2 -20Sinx=0
#include
#include
using namespace std;

double f(double x) {


return x*x - 20*sin(x);
}

int main() {


double a, b, m;
int k = 0;
double e = 0.001;

cout << "a = "; cin >> a;


cout << "b = "; cin >> b;

while ((fabs(b-a) > e)) {


m = (a + b)/2.;
k++;
if (f(m) == 0)
break;

if (f(a) * f(m) < 0)


b = m;
else
a = m;
}
cout << "x = " << m << endl;
cout << "k = " << k << endl;

}




    1. x3+0.2x2+0.5x+0.8=0

#include
#include
using namespace std;

double f(double x) {


return pow(x,3)+0.2*pow(x,2)+(0.5*x)+0.8;
}

int main() {


double a, b, m;
int k = 0;
double e = 0.001;

cout << "a = "; cin >> a;


cout << "b = "; cin >> b;

while ((fabs(b-a) > e)) {


m = (a + b)/2.;
k++;
if (f(m) == 0)
break;

if (f(a) * f(m) < 0)


b = m;
else
a = m;
}
cout << "x = " << m << endl;
cout << "k = " << k << endl;

}



3. Quyidagi integrallarni: 1)to‘rtburchak usulida; 2)trapetsiya usulida;

Download 30.53 Kb.

Do'stlaringiz bilan baham:




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