/*Write a C program to find the roots of a quadratic equation.*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float a,b,c,r1,r2,disc;
clrscr();
printf("Enter the a, b, c values \n");
scanf("%f%f%f",&a,&b,&c);
disc=b*b-4*a*c;/*to find discriminant*/
if(disc<0)/*distinct roots*/
printf("\n\n Roots are IMAGINARY\n");
else
{
r1=(-b+sqrt(disc))/(2*a);
r2=(-b-sqrt(disc))/(2*a);
printf("\n\n Root1 = %5.2f\n\n Root2 = %5.2f\n",r1,r2);
}
getch();
}
output:
Enter the a, b, c values
3
-10
5
Root1 = 2.72
Root2 = 0.61
0 comments:
Post a Comment