Search:

Submit Article

# Program to find the roots of an equation ax2 + bx + c = 0

Posted By: Matheus Silva     Category: C Programming     Views: 36838

## Code for Program to find the roots of an equation ax2 + bx + c = 0 in C Programming

```#include<stdio.h>
#include<conio.h>
#include<math.h>

int 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 ALPHA=BETA=%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();

return 0;
}

Output:

(1)

Enter a: 12

Enter b: 2

Enter c: 34

Imaginary Roots

(2)

Enter a: 2

Enter b: 6

Enter c: 2

Alpha = -0.381966
Beta = -2.618034

(3)

Enter a: 2

Enter b: 4

Enter c: 2

ALPHA=BETA= -1.000000```
Share:

Didn't find what you were looking for? Find more on Program to find the roots of an equation ax2 + bx + c = 0 Or get search suggestion and latest updates.

 Matheus Silva author of Program to find the roots of an equation ax2 + bx + c = 0 is from Salvador, Brazil. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!