Interview Questions   Tutorials   Discussions   Programs

# C - Write a c program to find the roots of a quadratic equation ax2 + bx + c = 0?

199
views
asked marvit August 24, 2014 09:49 AM

Write a c program to find the roots of a quadratic equation ax2 + bx + c = 0?

``````/* program for finding roots of an equation */
#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
float a,b,c,alf,bt,dlt;
clrscr();

printf("\n Enter a: ");
scanf("%f",&a);

printf("\n Enter b: ");
scanf("%f",&b);

printf("\n Enter c: ");
scanf("%f",&c);

dlt=b*b-4*a*c;

if(dlt==0)
{
printf("\n roots are equal ,%f",-b/(2*a));
}
elseif(dlt<0)
{
printf("\n Imaginary Roots");
}
else
{
alf=(-b+sqrt(dlt))/(2*a);
bt=(-b-sqrt(dlt))/(2*a);
printf("\n\n Alpha = %f\n Beta=%f\n",alf,bt);
}

getch();

}``````
flag

### Join with account you already have

Preview

Online-Classroom Classes
www.writeabc.com

1 person following this question

Question tags

c × 1

Asked 2 years and 3 months ago ago
Number of Views -199