100% prog to find and print roots of quadratic equation
//program to print roots of quadratic equation ax^2+bx+c=0; (a!=0)
#include <stdio.h>
void main()
{
float a,b,c,temp,root1,root2;
printf("\n enter the coefficients of the polynomial ax^2+bx+c where a!=0: ");
scanf("%f%f%f",&a,&b,&c);
temp=b*b-4*a*c;
if(temp>=0) //roots are real
{
root1=(-b+sqrt(temp))/(2*a);
root2=(-b-sqrt(temp))/(2*a);
printf("\n root1=%f root2= %f",root1,root2);
}
else
{
printf("\n root1 = %f",-b/(2*a)); //only real part
printf("+i %f",sqrt(temp)/(2*a));
printf("\n root2 = %f",-b/(2*a)); //only real part
printf("-i %f",sqrt(temp)/(2*a));
}
}
#include <stdio.h>
void main()
{
float a,b,c,temp,root1,root2;
printf("\n enter the coefficients of the polynomial ax^2+bx+c where a!=0: ");
scanf("%f%f%f",&a,&b,&c);
temp=b*b-4*a*c;
if(temp>=0) //roots are real
{
root1=(-b+sqrt(temp))/(2*a);
root2=(-b-sqrt(temp))/(2*a);
printf("\n root1=%f root2= %f",root1,root2);
}
else
{
printf("\n root1 = %f",-b/(2*a)); //only real part
printf("+i %f",sqrt(temp)/(2*a));
printf("\n root2 = %f",-b/(2*a)); //only real part
printf("-i %f",sqrt(temp)/(2*a));
}
}
ఔట్పుట్ తెరమీద
enter the coefficients of the polynomial ax^2+bx+c where a!=0: 1 3 2root1=-1.000000 root2= -2.000000
enter the coefficients of the polynomial ax^2+bx+c where a!=0: 1 1 1
root1 = -0.500000+i 0.866025
root2 = -0.500000-i 0.866025
root1 = -0.500000+i 0.866025
root2 = -0.500000-i 0.866025
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.