0% found this document useful (0 votes)
27 views

C Experiment

This program takes in coefficients a, b, and c of a quadratic equation and uses the quadratic formula to find the roots. It calculates the discriminant and uses its sign to determine if the roots are real and equal, real and distinct, or imaginary. It then prints the appropriate roots.

Uploaded by

sandeep129110
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

C Experiment

This program takes in coefficients a, b, and c of a quadratic equation and uses the quadratic formula to find the roots. It calculates the discriminant and uses its sign to determine if the roots are real and equal, real and distinct, or imaginary. It then prints the appropriate roots.

Uploaded by

sandeep129110
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Find roots of quadratic equation.

#include <stdio.h>
#include<conio.h>
#include <math.h>
void main()
{
float a,b,c,x1,x2,disc;
printf("ent the value of coeffecient(a,b and c)\n");
scanf("%f%f%f",&a,&b,&c);
disc=b*b-4*a*c;
if (disc==0)
{
printf("roots are real and equal\n" );
x1=-b/(2*a);
x2=x1;
printf("1st root =%f\n",x1);
printf("2nd root =%f\n",x2);
}
else if (disc>0)
{
printf("roots are real and disntict\n");
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("1st root =%f\n",x1);
printf("2nd root =%f\n",x2);
}
else
{
printf("imaginary roots\n");
x1=-b/(2*a);
x2=sqrt(fabs(disc))/(2*a);
printf("1st root =%f+i%f\n",x1,x2);
printf("2nd root =%f-i%f\n",x1,x2);
}
}

You might also like