program to solve quadratic equation through c
#include<stdio.h>
#include<math.h>
int main(){
float a,b,c,d,real,imag,r1,r2;
int k;
printf("enter the values of a,b and c:");
scanf("%f%f%f",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d<0)
k=1;
if(d==0)
k=2;
if(d>0)
k=3;
switch(k){
case 1:
printf("\n The roots are complex");
real=-b/(2*a);
imag=(sqrt(-d))/(2*a);
printf("\n One root is %f+%f*i \n",real,imag);
printf("\n Another root is %f-%f*i \n",real,imag);
break;
case 2:
printf("\n The roots are equal");
printf("\n The root is %f",(-b/2*a));
break;
case 3:
printf("\n The roots real and unequal");
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("\n one root is %f",r1);
printf("\n one root is %f",r2);
break;
}
return(0);
}
#include<stdio.h>
#include<math.h>
int main(){
float a,b,c,d,real,imag,r1,r2;
int k;
printf("enter the values of a,b and c:");
scanf("%f%f%f",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d<0)
k=1;
if(d==0)
k=2;
if(d>0)
k=3;
switch(k){
case 1:
printf("\n The roots are complex");
real=-b/(2*a);
imag=(sqrt(-d))/(2*a);
printf("\n One root is %f+%f*i \n",real,imag);
printf("\n Another root is %f-%f*i \n",real,imag);
break;
case 2:
printf("\n The roots are equal");
printf("\n The root is %f",(-b/2*a));
break;
case 3:
printf("\n The roots real and unequal");
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("\n one root is %f",r1);
printf("\n one root is %f",r2);
break;
}
return(0);
}
Post a Comment