thieumao

PT bậc 2 - có chú thích

May 24th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include<stdio.h> // include khai báo thư viện
  2. #include<conio.h>
  3. #include<math.h>
  4. void main()
  5. {
  6. float x1,x2,a,b,c,delta; //float là khai báo biến kiểu số thực, int là kiểu số nguyên
  7. printf("nhap he so a b c:"); // printf la xuat chu ra man hinh giong write trong Pascal
  8. scanf("%f%f%f",&a,&b,&c); // đọc 3 giá trị a,  b, c từ bàn phím giống readln trong pascal, %f là kiểu số thực %d là kiểu số nguyên
  9. if (a!=0) // a!=0 là a khác 0
  10. {
  11.  delta=b*b-4*a*c;
  12.  if (delta<0)
  13.   printf("\nphuong trinh vo nghiem");
  14.  if (delta>0)
  15.   {
  16.    x1=(-b-sqrt(delta))/(2*a);
  17.    x2=(-b+sqrt(delta))/(2*a);
  18.    printf("\nphuong trinh co 2 nghiem phan biet:");
  19.    printf("x1=%2.3f   ,x2=%2.3f",x1,x2);
  20.   }
  21.  if (delta==0)
  22.    printf("phuong trinh co nghiem kep la : %f",-b/(2*a) );
  23.  }
  24.  else
  25.   {
  26.   if (b==0)
  27.    printf("phuong trinh vo nghiem");
  28.   else
  29.    printf("phuong trinh co ngihem %f",-c/b);
  30.   }
  31.  
  32.  
  33. getch();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment