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

Answer Posted / patel mac p

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a,b,c,d;
float x1,x2,root;
printf("\nEnter the value of a,b,c");
scanf("%d %d %d",&a,&b,&c);
d=(b*b)-(4*a*c);
if(a==0&&b==0)
{
printf("\nNO SOLUTION");
}
else
if(a==0&&b!=0)
{
root=-c/b;
printf("ROOT=%f",root);
}
else
if(d>=0)
{
printf("\nROOTS ARE REAL");
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("\nX1=%f",x1);
printf("\nx2=%f",x2);
}
else
if(d<0)
{
printf("\nTHIS EQUATION HAS IMAGINARY ROOTS");
}
getch();
}

Is This Answer Correct ?    11 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When we use void main and int main?

588


What are the advantages and disadvantages of pointers?

578


Is it acceptable to declare/define a variable in a c header?

688


Why we use stdio h in c?

584


How to write c functions that modify head pointer of a linked list?

545






How do you print only part of a string?

615


What is return type in c?

639


What is difference between structure and union?

601


What are the different types of objects used in c?

577


Which are low level languages?

636


What is the scope of global variable in c?

558


What is the size of a union variable?

600


Is it possible to have a function as a parameter in another function?

599


How we can insert comments in a c program?

632


What is the difference between mpi and openmp?

736