AIM
To
write a C program for finding roots of a quadratic equation
ALGORITHM
Step
1: Start
Step
2: Read values of a,b and c
Step
3: Calculate value of discriminant
D←b*b-(4*a*c)
Step
4: if D←0
Root←(-1*b/(2*a))
Display Root
Step
5: if D>0
Root1←(-b+√D)/2a
Root2←(-b-√D)/2a
Display Root1 and Root2
Step
6: if D<0, Display ‘roots are imaginary’
Step
7: Stop
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<math.h>
void
main()
{
float a,b,c,d,r1,r2;
printf("Enter the values of
a,b,c\n");
scanf("%f%f%f",&a,&b,&c);
d=(b*b)-(4*a*c);
r1=((-1*b)+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("Roots are real and distinct:\n%f\n%f",r1,r2);
}
else
if(d==0)
{
r1=-b/(2*a);
printf("Roots are real and equal:\n%f",r1);
}
else
{
printf("The roots are imaginary");
}
getch();
}
RESULT
The C program for findng the roots of a
quadratic equation is completed successfully and the output is verified.
No comments:
Post a Comment