//WAP to calculate the roots of quadratic equation//
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a, b, c, d, r1, r2;
printf("Enter the value of a, b, c\n");
scanf("%f%f%f", &a, &b, &c);
d=(b*b) - (4*a*c);
if(d<0)
{
printf("Roots are Imaginary\n");
}
else if (d=0)
{
printf("Roots are real and equal\n");
r1= -b/(2*a);
r2= r1;
printf("Roots are:\nr1=%f\nr2=%f", r1, r2);
}
else (d>0)
{
printf("Roots are real and distinct\n");
r1= (-b+sqrt(d))/(2*a);
r2= (-b-sqrt(d))/(2*a);
printf("Roots are:\nr1=%f\nr2=%f", r1, r2);
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a, b, c, d, r1, r2;
printf("Enter the value of a, b, c\n");
scanf("%f%f%f", &a, &b, &c);
d=(b*b) - (4*a*c);
if(d<0)
{
printf("Roots are Imaginary\n");
}
else if (d=0)
{
printf("Roots are real and equal\n");
r1= -b/(2*a);
r2= r1;
printf("Roots are:\nr1=%f\nr2=%f", r1, r2);
}
else (d>0)
{
printf("Roots are real and distinct\n");
r1= (-b+sqrt(d))/(2*a);
r2= (-b-sqrt(d))/(2*a);
printf("Roots are:\nr1=%f\nr2=%f", r1, r2);
}
getch();
}
- The Input and Output of this program is shown in the pictures below:- INPUT
OUTPUT




Comments
Post a Comment