Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h> // include khai báo thư viện
- #include<conio.h>
- #include<math.h>
- void main()
- {
- 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
- printf("nhap he so a b c:"); // printf la xuat chu ra man hinh giong write trong Pascal
- 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
- if (a!=0) // a!=0 là a khác 0
- {
- delta=b*b-4*a*c;
- if (delta<0)
- printf("\nphuong trinh vo nghiem");
- if (delta>0)
- {
- x1=(-b-sqrt(delta))/(2*a);
- x2=(-b+sqrt(delta))/(2*a);
- printf("\nphuong trinh co 2 nghiem phan biet:");
- printf("x1=%2.3f ,x2=%2.3f",x1,x2);
- }
- if (delta==0)
- printf("phuong trinh co nghiem kep la : %f",-b/(2*a) );
- }
- else
- {
- if (b==0)
- printf("phuong trinh vo nghiem");
- else
- printf("phuong trinh co ngihem %f",-c/b);
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment