Advertisement
Guest User

Sanhpv

a guest
Dec 21st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.10 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5.         float a,b,c,delta,x1,x2,x3,x4,t,t1,t2;
  6.         printf("nhap a,b,c voi a khac 0\n");
  7.         scanf("%f%f%f",&a,&b,&c);
  8.         delta=b*b-4*a*c;
  9.         if(delta<0) printf("phuong trinh vo nghiem");
  10.         else if (delta==0)
  11.         {
  12.                 t=-b/(2*a);
  13.                 if (b==0)
  14.                 printf("phuong trinh co mot nghiem la 0");            
  15.         }
  16.         else
  17.         {
  18.                 t1=(-b+sqrt(delta))/(2*a);
  19.                 t2=(-b-sqrt(delta))/(2*a);
  20.                 if(t1<0&&t2<0) printf("phuong trinh vo nghiem");
  21.                 else if(t1<0&&t2>0)
  22.                 {
  23.                         x1=sqrt(t2);
  24.                         x2=-sqrt(t2);
  25.                         printf("phuong trinh co 2 nghiem la:\nx1=%f\nx2=%f",x1,x2);
  26.                 }
  27.                 else if(t1>0&&t2<0)
  28.                 {
  29.                         x1=sqrt(t1);
  30.                         x2=-sqrt(t1);
  31.                         printf("phuong trinh co 2 nghiem la:\nx1=%f\nx2=%f",x1,x2);    
  32.                 }
  33.                 else if(t1==0&&t2<0) printf("phuong trinh co 1 nghiem la: 0");
  34.                 else if(t1==0&&t2>0)
  35.                 {
  36.                         x1=0;
  37.                         x2=sqrt(t2);
  38.                         x3=-sqrt(t2);
  39.                         printf("phuong trinh co 3 nghiem la:\nx1=%f\nx2=%f\nx3=%f",x1,x2,x3);
  40.                 }
  41.                 else if(t2==0&&t1<0) printf("phuong trinh co 1 nghiem la: 0");
  42.                 else if(t2==0&&t1>0)
  43.                 {
  44.                         x1=0;
  45.                         x2=sqrt(t1);
  46.                         x3=-sqrt(t1);
  47.                         printf("phuong trinh co 3 nghiem la:\nx1=%f\nx2=%f\nx3=%f",x1,x2,x3);
  48.                 }
  49.                 else
  50.                 {
  51.                         x1=sqrt(t1);
  52.                         x2=-sqrt(t1);
  53.                         x3=sqrt(t2);
  54.                         x4=-sqrt(t2);
  55.                         printf("phuong trinh co 4 nghiem la:\nx1=%f\nx2=%f\nx3=%f\nx4=%f",x1,x2,x3,x4);
  56.                 }
  57.         }      
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement