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


Please Help Members By Posting Answers For Below Questions

What is a loop?

556


What is bubble sort in c?

639


Why are algorithms important in c program?

620


Explain that why C is procedural?

660


How variables are declared in c?

571






Create a structure to specify data on students as given below: Roll number, Name, Department, Course, and Year of joining. Assume that there are not more than 450 students in the collage. (a) Write a function to print the names of all students who joined in the last 3 years. (b) Write a function to print the data of a student whose roll numbers are divisible by 4.

604


#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }

718


Why array is used in c?

553


What are the ways to a null pointer can use in c programming language?

592


What is f'n in math?

621


Which header file is used for clrscr?

582


Tell us two differences between new () and malloc ()?

614


What is an lvalue?

636


Why do we use & in c?

593


What is the c value paradox and how is it explained?

575