#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c,x,y;
int ch;
cout<<"1.first root of eqn\n";
cout<<"2.second root of eqn\n";
cout<<"enter your choice\n";
cin>>ch;
switch(ch)
{
case 1:
cout<<"enter the coefficient of x^2\n";
cin>>a;
cout<<"enter the coefficient of x\n";
cin>>b;
cout<<"enter the constant term\n";
cin>>c;
x=-b+sqrt(b*b-4*a*c)/2*a;
cout<<"the first root will be\n"<<x;
break;
case 2:
cout<<"enter the coefficient of x^2\n";
cin>>a;
cout<<"enter the coefficient of x\n";
cin>>b;
cout<<"enter the constant term\n";
cin>>c;
y=-b-sqrt(b*b-4*a*c)/2*a;
cout<<"the second root will be\n"<<y;
break;
default:
cout<<"the entered choice is invalid";
}
getch();
}
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c,x,y;
int ch;
cout<<"1.first root of eqn\n";
cout<<"2.second root of eqn\n";
cout<<"enter your choice\n";
cin>>ch;
switch(ch)
{
case 1:
cout<<"enter the coefficient of x^2\n";
cin>>a;
cout<<"enter the coefficient of x\n";
cin>>b;
cout<<"enter the constant term\n";
cin>>c;
x=-b+sqrt(b*b-4*a*c)/2*a;
cout<<"the first root will be\n"<<x;
break;
case 2:
cout<<"enter the coefficient of x^2\n";
cin>>a;
cout<<"enter the coefficient of x\n";
cin>>b;
cout<<"enter the constant term\n";
cin>>c;
y=-b-sqrt(b*b-4*a*c)/2*a;
cout<<"the second root will be\n"<<y;
break;
default:
cout<<"the entered choice is invalid";
}
getch();
}
No comments:
Post a Comment