Advertisement
sangvo

BT C giai Pt bac 2

Nov 23rd, 2015
3,701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // bai tap giai phuong trinh bac hai
  3. #include<math.h>
  4. #include<conio.h>
  5. #include<stdio.h>
  6. void main()
  7. {
  8. // Khai bao bien
  9. float a,b,c,delta;
  10. //In ra man hinh
  11. printf("Cho biet he so a = ");
  12. scanf("%f", &a);
  13. printf("Cho biet he so b = "); scanf("%f", &b);
  14. printf("Cho biet he so c = "); scanf("%f", &c);
  15. // tinh delta
  16. delta = b*b - 4*a*c;
  17. if (delta < 0)
  18.            printf("Phuong trinh vo nghiem");
  19. else if (delta == 0)
  20.            printf("Phuong trinh co nghiem kep x1 = x2 = %0.2f", -b/(2*a));
  21.   else{
  22.            printf ("Phuong trinh co 2 nghiem phan biet:\n x1 = %0.2f", (-b + sqrt(delta))/(2*a));
  23.                        printf ("\nx1 = %0.2f", (-b - sqrt(delta))/(2*a));
  24.   }
  25.   getch();
  26. //create by Sangvo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement