📄 ex11-06.cpp
字号:
//EX11-06.cpp
#include <iostream.h> //cout,cin
#include <conio.h> // getch()
#include <math.h> //sqrt
struct equation
{ float a,b,c;
float x1,x2,r,v; //r :real part, v:virtual part
};
void list_equ(equation);
void main()
{ equation equ;
float judge;
equ.r=equ.v=0;
cout <<"a,b,c=";
cin >> equ.a >>equ.b >> equ.c;
judge=equ.b*equ.b-4*equ.a*equ.c;
if (judge==0)
equ.x1=equ.x2=-equ.b/(2*equ.a);
if (judge>0)
{ equ.x1=(-equ.b+sqrt(judge))/(2*equ.a);
equ.x2=(-equ.b-sqrt(judge))/(2*equ.a);
}
if (judge<0)
{ equ.r=-equ.b/(2*equ.a);
equ.v=sqrt(-judge)/(2*equ.a);
}
list_equ(equ);
getch();
}
void list_equ(equation equ)
{ if (equ.r!=0)
{ cout<<"x1="<<equ.r <<"+"<<equ.v<<"i\n"
<<"x2="<<equ.r <<"-"<<equ.v<<"i\n";
} else
{ cout << "x1="<< equ.x1 << endl
<< "x2="<< equ.x2 << endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -