PROGRAM
write a program to find the numbers when their sum (S) and product (P) is known.#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
system("cls");
int S,P,a,b,c;
cout<<"Enter the sum of two numbers :";
cin>>S;
cout<<"Enter product of two numbers :";
cin>>P;
if (S>0)
cout<<"Quadratic eqn formed is:x*x-"<<S<<"+"<<P<<endl;
else
cout<<"Quadratic eqn formed is:x*x+"<<S<<"+"<<P<<endl;
a=1;
b=-S;
c=P;
cout<<"coefficients are:a="<<a<<",b="<<b<<",c="<<c<<endl;
double discriminant=b*b-4.0*a*c;
double sqroot = sqrt(discriminant);
double root1 =(-b+sqroot)/(2.0*a);
double root2 =(-b-sqroot)/(2.0*a);
cout<<"Two number whose sum is "<<S<<" & product is "<<P<<" are:"<<endl;
cout<<"number 1 : "<<root1<<", number 2 : "<<root2<<endl;
getch();
return 0;
}
========================================================================
OUTPUT:
Enter the sum of two numbers :10
Enter product of two numbers :24
Quadratic eqn formed is:x*x-10+24
coefficients are:a=1,b=-10,c=24
Two number whose sum is 10 & product is 24 are: number 1 : 6, number 2 : 4
========================================================================
No comments:
Post a Comment