I like to learn new technologies. These posts are for my own reference (I have habit of forgetting). If anybody finds these posts useful, then it will surely make me HaPpY.
Showing posts with label number. Show all posts
Showing posts with label number. Show all posts
Tuesday, March 20, 2012
Thursday, March 15, 2012
Program to real roots of quadratic equation with output
// d = b^2 - 4ac
#include <iostream>
#include <cmath> //when we used c library in c++
using namespace std;
int main()
{
float a, b, c, d, root1, root2;
cout << "\n Enter the value of a, b, c: " ;
cin >> a >> b >> c;
d = b*b - 4*a*c;
cout << "\n discriminant is: " << d ;
if ( d<0 )
{
cout << "\n Roots are imagenary.";
}
else
{
root1 = (-b + sqrt(d)) / (2*a);
root2 = (-b - sqrt(d)) / (2*a);
cout << "\n root1 is: " << root1 << "\n root2 is: " << root2 << endl;
}
return 0;
}
OUTPUT:
#include <iostream>
#include <cmath> //when we used c library in c++
using namespace std;
int main()
{
float a, b, c, d, root1, root2;
cout << "\n Enter the value of a, b, c: " ;
cin >> a >> b >> c;
d = b*b - 4*a*c;
cout << "\n discriminant is: " << d ;
if ( d<0 )
{
cout << "\n Roots are imagenary.";
}
else
{
root1 = (-b + sqrt(d)) / (2*a);
root2 = (-b - sqrt(d)) / (2*a);
cout << "\n root1 is: " << root1 << "\n root2 is: " << root2 << endl;
}
return 0;
}
OUTPUT:
Subscribe to:
Posts (Atom)