Powered By Blogger

martes, 11 de diciembre de 2012

Programa que realiza una operacion de segundo grado.


//Programa que realiza una operacion de segundo grado.
#include<stdio.h>
#include<iostream.h>
#include<math.h>
#include<conio.h>

void main(void)
{
char r;
float a,b,c,w,x,y,z,d,e,x1,x2;
do
{
clrscr();
cout<<"Coeficiente de x^2:";
cin>>a;
cout<<"Coeficiente de x:";
cin>>b;
cout<<"Coeficiente independiente:";
cin>>c;
if(a==0)
{
x=-1*(c/b);
clrscr();
cout<<"Solucion: x="<<x;
getch();
}
else
{
if(b==0)
{
if(c<0&&a>0||c>0&&a<0)
{
x=sqrt((c/a)*-1);
clrscr();
cout<<"Solucion: X="<<x;
getch();
}
else
{
x=sqrt(c/a);
clrscr();
cout<<"Solucion: X="<<x<<"i";
getch();
}
}
else
{
w=b*b;
y=4*a*c;
z=2*a;
if(w>y)
{
x1=(-b+sqrt(w-y))/z;
x2=(-b-sqrt(w-y))/z;
clrscr();
cout<<"Soluciones:"<<endl<<"X1="<<x1<<endl<<"X2="<<x2;
getch();
}
else
{
d=sqrt(-1*(w-y))/z;
e=(-b/z);
//x1=e+d;
//x2=e-d;
clrscr();
cout<<"Soluciones:"<<endl<<"X1="<<e<<"+"<<d<<"i"<<endl<<"X2="<<e<<"-"<<d<<"i";
getch();
}
}
}
clrscr();
cout<<"...Deseas hacer otra operacion?(s/n):";
cin>>r;
}
while(r=='s');
}

No hay comentarios:

Publicar un comentario