30/09/2018, 20:12
Mình run nhưng k dc như mong muốn :(, pt bậc 3, cảm ơn các bạn
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(){
float a,b,c,d;
printf("a= ");
scanf("%f",&a);
printf("
b= ");
scanf("%f",&b);
printf("
c= ");
scanf("%f",&c);
printf("
d= ");
scanf("%f",&d);
printf("
giai pt ax3+bx2+cx+d=0");
if(a==0 && b==0) printf("pt vo nghiem");
else if((a==0 && b!=0) || (a==0 && b!=0 && c==0)) printf("
pt co nghiem la x= %.1f",-c/b);
else if (a==0 && b==0 && c==0 ) printf("
pt co vo so nghiem");
else{
float delta,x1,x2,x3,x4,x5,x6,k;
delta=(float)pow(b,2)-(3*a*c);
k=(float)(9*a*b*c-2*pow(b,3)-27*pow(a,2)*d)/(2*sqrt(pow(abs(delta),3)));
x1=(2*sqrt(delta)*cos((acos(k)/3))-b)/(3*a);
x2=(2*sqrt(delta)*cos((acos(k)/3)-(2*3.14)/3)))-b)/(3*a);
x3=(2*sqrt(delta)*cos((acos(k)/3)+(2*3.14)/3)))-b)/(3*a);
float x4=((sqrt(delta)*abs(k))/(3*a*k))*(pow(abs(k)+sqrt(pow(k,2)-1),(1/3))+pow(abs(k)-sqrt(pow(k,2)-1),(1/3)))-(b/(3*a));
x5=(-b+pow(pow(b,3)-27*pow(a,2)*d,(1/3)))/(3*a);
float x6=(sqrt(abs(delta))/(3*a))*(pow(k+sqrt(pow(k,2)+1),(1/3))+pow(k-sqrt(pow(k,2)+1),(1/3)))-(b/(3*a));
if(delta>0) {
if (abs(k)<=1) printf("
pt co 3 nghiem x1= %.2f x2= %.2f x3= %.2f",x1,x2,x3);
else printf("
pt co 1 nghiem duy nhat x= %.2f",x4);
}
if(delta=0) printf("
co 1 nghiem kep x= %.2f",x5);
if(delta<0) printf("
pt co 1 nghiem duy nhat x= %.2f",x6);
getch();
}
Bài liên quan