program to find the roots of a quadratic equation

Answer Posted / vikas tiwari

#include <iostream.h>
#include <conio.h>
#include <math.h>
int main()
{
clrscr();
float a,b,c,d,root1,root2;
cout << "Enter the 3 coefficients a, b, c : " << endl;
cin>>a>>b>>c;
if(!a){
if(!b)
cout << "Both a and b cannot be 0 in ax^2 + bx + c = 0" << "\n";
else
{
d=-c/b;
cout << "The solution of the linear equation is : " << d << endl;
}
}
else
{
d=b*b-4*a*c;
if(d>0)
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
cout << "The first root = " << root1 << endl;
cout << "The second root = " << root2 << endl;
}
getch();
return 0;
}

Is This Answer Correct ?    32 Yes 20 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1068


Design an implement of the inputs functions for event mode

2960


To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

496


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

2138


How to palindrom string in c language?

8844






What is full form of PEPSI

1865


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

3069


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

3710


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

2019


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

1796


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

2325


How can I Create a C program in splitting set of characters to specific subsets. Example: INPUT SET OF CHARACTERS: Therefore, my dear brothers and sisters, stand firm. Let nothing move you. Always give yourselves fully to the work of the Lord, because you know that your labor in the Lord is not in vain. SPLIT INTO HOW MANY CHARACTERS PER SUBSETS: 10 OUTPUT: Therefore, my dear b rothers an d sisters, stand fir m. Let not hing move you. Alway s give you rselves fu lly to the work of t he Lord, b ecause you know that your labo r in the L ord is not in vain.

1928


What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql

2408


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

2994


write a program for area of circumference of shapes

2029