Monday 4 February 2013

IT series Control Structure Part 13:


Find the roots of the Quadratic Equation:
ax2+bx+C=0

#include<iostream.h>
#include<stdio.h>
#include<math.h>
void main()
{
printf("This program solve the quadratic equation and find out the real roots of the equation\n");
cout<<"Kindly just enter the coeffint of the equation ax^2+bx+c\n\n";
int a,b,c;
cout<<"Enter units\n\n";cin>>a>>b>>c;
float z,x,v,n;
x=pow(b,2)-4*a*c;
z=sqrt(x);
    if(z>=0)
{
v=((-b+z)/(2*a));
cout<<"This is first root\n"<<v<<endl;
v=((-b-z)/(2*a));
cout<<"This is second root of this quadratic equation\n\n"<<v<<endl;
}
else
cout<<"Roots are not real\n";
}


No comments:

Post a Comment

Comments please: