Advertisement
nguyenhappy92

Giải phương trình ax^2+bx+c=0

Oct 6th, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. // Giai phuong trinh ax^2 + bx + c =0
  2. // Khai bao cac thu vien
  3. #include<stdio.h>
  4. #include<conio.h>
  5. #include<math.h>
  6.  
  7. void main()
  8. {
  9. int a,b,c;
  10. scanf("%d%d%d",&a,&b,&c);
  11.  
  12. if(a==0)
  13. {
  14. if(b==0)
  15. {
  16. if(c==0)
  17. {
  18. printf("PT co nghiem tuy y");
  19. }
  20. else
  21. {
  22. printf(" PT vo nghiem");
  23. }
  24. }
  25. else
  26. {
  27. printf("PT co nghiem duy nhat: %.2f", (float) -b/a);
  28. }
  29. }
  30. else
  31. {
  32. float delta =(float) (b*b) -(4*a*c) ;
  33. if(delta <0)
  34. {
  35. printf(" PT vo nghiem");
  36. }
  37. else
  38. {
  39. if(delta==0)
  40. {
  41. printf(" PT co nghiem kep x1=x2 : %.2f", (float) -b/(2*a));
  42. }
  43. else
  44. {
  45. float x1=(float)(-b +sqrt(delta))/(2*a);
  46. float x2=(float)(-b - sqrt(delta))/(2*a);
  47. printf("PT co 2 nghiem phan biet: x1= %.2f\n, x2=%.2f\n", x1,x2);
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement