Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- float a,b,c,delta,x1,x2,x3,x4,t,t1,t2;
- printf("nhap a,b,c voi a khac 0\n");
- scanf("%f%f%f",&a,&b,&c);
- delta=b*b-4*a*c;
- if(delta<0) printf("phuong trinh vo nghiem");
- else if (delta==0)
- {
- t=-b/(2*a);
- if (b==0)
- printf("phuong trinh co mot nghiem la 0");
- }
- else
- {
- t1=(-b+sqrt(delta))/(2*a);
- t2=(-b-sqrt(delta))/(2*a);
- if(t1<0&&t2<0) printf("phuong trinh vo nghiem");
- else if(t1<0&&t2>0)
- {
- x1=sqrt(t2);
- x2=-sqrt(t2);
- printf("phuong trinh co 2 nghiem la:\nx1=%f\nx2=%f",x1,x2);
- }
- else if(t1>0&&t2<0)
- {
- x1=sqrt(t1);
- x2=-sqrt(t1);
- printf("phuong trinh co 2 nghiem la:\nx1=%f\nx2=%f",x1,x2);
- }
- else if(t1==0&&t2<0) printf("phuong trinh co 1 nghiem la: 0");
- else if(t1==0&&t2>0)
- {
- x1=0;
- x2=sqrt(t2);
- x3=-sqrt(t2);
- printf("phuong trinh co 3 nghiem la:\nx1=%f\nx2=%f\nx3=%f",x1,x2,x3);
- }
- else if(t2==0&&t1<0) printf("phuong trinh co 1 nghiem la: 0");
- else if(t2==0&&t1>0)
- {
- x1=0;
- x2=sqrt(t1);
- x3=-sqrt(t1);
- printf("phuong trinh co 3 nghiem la:\nx1=%f\nx2=%f\nx3=%f",x1,x2,x3);
- }
- else
- {
- x1=sqrt(t1);
- x2=-sqrt(t1);
- x3=sqrt(t2);
- x4=-sqrt(t2);
- printf("phuong trinh co 4 nghiem la:\nx1=%f\nx2=%f\nx3=%f\nx4=%f",x1,x2,x3,x4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement