1-amaliy ishi mavzu: Algoritmlarni loyixalashga. Algoritm korrekt va samaradorligini baholash. Kvadrat tenglama ildizlarini aniqlash algoritmi. Uchburchak yuzasi uchun Geron formulasi. Ishdan maqsad



Yüklə 0,76 Mb.
səhifə3/3
tarix07.04.2023
ölçüsü0,76 Mb.
#94578
1   2   3
1-amaliyot.kvadrat va kubik tenglamalar

Amaliyot topshiriqlari:
1.Kvadrat teglama
3.1.Koeffitsiyentlari a=-1, b= -6, c=3 bo’lgan kvadrat tenglama ildizlari topilsin;
#include
#include

using namespace std;


int main()
{
float a,b,c,d,x1,x2;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
cout<<"c=";cin>>c;
d=b*b-4*a*c;
if (d<0)
cout<<("tenglamaning haqiqiy ildizlari yoq");
if (d>0)
x1=(-b-sqrt(d))/(2*a);
x2=(-b+sqrt(d))/(2*a);
cout <<"x1=" <cout<<"x2=" <if (d=0)
x1=-b/(2*a);
cout <<"x1=x2"<return 0;
}

3.2. Tomonlari a=2, b=9, c=7 bo’lgan uchburchak yuzi topilsin.
#include
#include
using namespace std;

int main()


{
float side1, side2, side3, area, s;
cout << "\n\n Find the area of any triangle using Heron's Formula :\n";
cout << "----------------------------------------------------------\n";
cout<<" Input the length of 1st side of the triangle : ";
cin>>side1;
cout<<" Input the length of 2nd side of the triangle : ";
cin>>side2;
cout<<" Input the length of 3rd side of the triangle : ";
cin>>side3;
s = (side1+side2+side3)/2;
area = sqrt(s*(s-side1)*(s-side2)*(s-side3));
cout<<" The area of the triangle is : "<< area << endl;
cout << endl;
return 0;
}

2.Kubik tenglama


Quyidagi tenglamalarning yechimlarini toping:

#include /* for sqrt(), fabs(), pow(), cos(), acos(). */
#include
//#define M_PI (3.141592653589793)
#define M_2PI (2.*M_PI)
using namespace std;
int Cubic(double *x,double a,double b,double c) {
double q,r,r2,q3;
q=(a*a-3.*b)/9.; r=(a*(2.*a*a-9.*b)+27.*c)/54.;
r2=r*r; q3=q*q*q;
if(r2double t=acos(r/sqrt(q3));
a/=3.; q=-2.*sqrt(q);
x[0]=q*cos(t/3.)-a;
x[1]=q*cos((t+M_2PI)/3.)-a;
x[2]=q*cos((t-M_2PI)/3.)-a;
return(3);
}
else {
double aa,bb;
if(r<=0.) r=-r;
aa=-pow(r+sqrt(r2-q3),1./3.);
if(aa!=0.) bb=q/aa;
else bb=0.;
a/=3.; q=aa+bb; r=aa-bb;
x[0]=q-a;
x[1]=(-0.5)*q-a;
x[2]=(sqrt(3.)*0.5)*fabs(r);
if(x[2]==0.) return(2);
return(1);
}
}
int main(){
double a,b,c;
double x[3];
cin>>a>>b>>c;
int d = Cubic(x,a,b,c);
cout<<"Ildizlar soni: "< for(int i = 0; i cout<<"x"< //cout< }
}

Yüklə 0,76 Mb.

Dostları ilə paylaş:
1   2   3




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin