program to find the roots of a quadratic equation

Answer Posted / gogol

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,x1,x2,disc,disc1;
clrscr();
printf("Let the quadratic equation is of the form:
a(x^2)+b(x)+c=0; Enter the values of the coefficients:\n");
printf("Enter the value of a: ");
scanf("%f",&a);
printf("Enter the value of b: ");
scanf("%f",&b);
printf("Enter the value of c: ");
scanf("%f",&c);
disc=b*b-4*a*c;
if(disc>0)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("The roots are distinct and they are: %3.3f and
%3.3f",x1,x2);
}
if(disc==0)
{
printf("The roots are equal and it is: %3.3f",-b/(2*a));
}
if(disc<0)
{
disc1=-disc;
x1=-b/(2*a);
x2=sqrt(disc1)/(2*a);
printf("The roots are complex and they are: %3.3f+%3.3fi
and %3.3f-%3.3fi",x1,x2,x1,x2);
}
getch();
}

Is This Answer Correct ?    9 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

3022


How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?

2012


Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??

1768


why nlogn is the lower limit of any sort algorithm?

2369


Design an implement of the inputs functions for event mode

2955






can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

2319


What is full form of PEPSI

1855


Develop a routine to reflect an object about an arbitrarily selected plane

2987


Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

3843


create a C-code that will display the total fare of a passenger of a taxi if the driver press enter,the timer will stop. Every 10 counts is 2 pesos. Initial value is 25.00

6304


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2253


Sir... please give some important coding questions asked by product companies..

1793


how to test pierrot divisor

2251


write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

2217


could you please send the program code for multiplying sparse matrix in c????

3063