Write a C program to find the roots of a quadratic equation.

Program Code:
#include<stdio.h>
#include<math.h>

void main()
{
float a,b,c,r1,r2,d;
printf("enter the values of equation:");
scanf("%f%f%f",&a,&b,&c);
if(a==0)
printf("\n enter non zero values");
else
{
d=b*b-4*a*c;
if(d>=0)
{
r1=((-b+sqrt(d))/(2*a));
r2=((-b-sqrt(d))/(2*a));
printf("\n the roots are=\t%f\t%f",r1,r2);
}
else
printf("\n roots are imaginary");
}
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: