You are on page 1of 2

#include<iostream.

h>
struct kq{
int count;//so nghiem
float x1,x2;//hai nghiem cua phuong trinh
};
kq ptb2(float a,float b,float c){
kq k;
if(a==0){
if(b==0){
if(c==0){
k.count=100;
}
else{
k.count=0;
}
}
else{
k.count=1;
k.x1=k.x2=c/b;
}
}
else{
float denta=b*b-4*a*c;
float e=sqrt(denta);
if(e>0){
k.count=2;
k.x1=(-b-e)/(2*a);
k.x2=(-b+e)/(2*a);
}
if(e==0){
k.count=1;
k.x1=k.x2=-b/(2*a);
}
else k.count=0;
}
return k;
}
main(){
float a,b,c;
cout<<"nhap he so cua tam thuc bac 2";
cout<<"nhap a : ";
cin>>a;
cout<<"nhap b : ";
cin>>b;
cout<<"nhap c : ";
cin>>c;
kq k;
k=ptb2(a,b,c);
cout<<k.count;
cout<<k.x1<<"\t"<<k.x2;
}
********************************************************************************
******************************************************
void Gpt(float a,float b,float c)
{
float deta;
float x1,x2;
if(a==0)
printf("Khong phai phuong trinh bac hai\n");
else

{
deta=b*b-4*a*c;
if(deta < 0)
printf("Phuong trinh vo nghiem\n");
if(deta==0)
{
x1=(float)(-b/(2*a));
printf("Phuong trinh co nghiem kep:%f",x1);
}
if(deta > 0)
{
x1=(float)(-b+sqrt(deta))/(2*a);
x2=(float)(-b-sqrt(deta))/(2*a);
printt("Phuong trinh co hai nghiem phan biet\n");
printf("x1= %6.2f\n",x1);
printf("x2= %6.2f\n",x2);
}
}
}

You might also like