write a c program to find the roots of a quadratic equation
ax2 + bx + c = 0
Answer Posted / sagarsp2010
// using sqrt in the program it needs header file <math.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,delta,alpha,beta;
clrscr();
printf("\nENTER THE VALUE OF a:");
scanf("%f",&a);
printf("\nENTER THE VALUE OF b:");
scanf("%f",&b);
printf("\nENTER THE VALUE OF c:");
scanf("%f",&c);
delta=(b*b)-(4*a*c);
if(delta>0)
{
alpha=(-b-sqrt(delta))/(2.0*a);
beta=(-b+sqrt(delta))/(2.0*a);
printf("\nalpha=%f",alpha);
printf("\nbeta=%f",beta);
}
else if(delta==0)
{
printf("\nROOTS ARE REAL");
alpha=-b/(2.0*a);
beta=-b/(2.0*a);
printf("\nalpha=%f",alpha);
printf("\nbeta=%f",beta);
}
else
{
printf("\nROOTS ARE IMAGINARY");
}
getch();
}
| Is This Answer Correct ? | 23 Yes | 25 No |
Post New Answer View All Answers
Do you have any idea how to compare array with pointer in c?
Explain 'bus error'?
When should the register modifier be used? Does it really help?
What are the 4 types of programming language?
Why we write conio h in c?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
Explain goto?
What is the size of structure in c?
What is the method to save data in stack data structure type?
Explain how can I open a file so that other programs can update it at the same time?
how is the examination pattern?
What type of function is main ()?
How do I swap bytes?
What is typedef struct in c?
What are the two types of functions in c?