Giải phương trình bậc hai ax^2+bx+c = 0
BÀI TOÁN
Giải phương trình bậc hai ax^2+bx+c=0 với các tham số a, b, c được nhập từ bàn phím.
CHƯƠNG TRÌNH THAM KHẢO
Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(){
float a,b,c,x1,x2,delta;
printf("Nhap cac he so a,b,c:");
scanf("%f%f%f",&a,&b,&c);
if (a==0)
if (b==0)
if (c==0)
printf("Pt vo so nghiem");
else
printf("Pt vo nghiem");
else printf("Pt co nghiem x=%.2f",-c/b);
else{
delta=b*b-4*a*c;
if (delta<0)
printf("Pt vo nghiem");
else
if(delta==0)
printf("Pt co nghiem kep x=%.2f",-b/(2*a));
else{
x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
printf("Pt co 2 nghiem phan biet x1=%.2f, x2=%.2f",x1,x2);
}
}
getch();
}