题目一:
#include
#include
using namespace std;
int main()
{
double a,b,c;
printf("请输入a = ");
scanf("%lf",&a);
printf("\n");
printf("请输入b = ");
scanf("%lf",&b);
printf("\n");
printf("请输入c = ");
scanf("%lf",&c);
printf("\n");
if(a==0){
printf("一元方程\n");
if(b==0&&c!=0)printf("无解\n");
else if(b==0)printf("无穷解\n");
else printf("X = %.2lf\n",c*(-1)/b);
}
else{
double d = b*b-4*a*c;
if(d==0){
printf("X1 = X2 = %.2lf\n",(-1)*b/a/2);
}
else if(d>0){
double e = (-1)*b/a/2;
double f = sqrt(d)/a/2;
printf("X1 = %.2lf X2 = %.2lf\n",e+f,e-f);
}
else{
double e = (-1)*b/a/2;
double f = sqrt(-d)/a/2;
printf("X1 = %.2lf+%.2lfi X2 = %.2lf-%.2lfi\n",e,f,e,f);
}
}
return 0;
}
题目二:
#include
#include
#include
using namespace std;
struct goods
{
char dm[5];
char mc[10];
int dj;
int sl;
int je;
void plan()
{
je = dj*sl;
}
bool operator<(goods a)
{
if(je==a.je)return strcmp(a.dm,dm);
else return je-a.je;
}
void print()
{
cout<
};
int main()
{
goods a[100];
int n,i=0;
char daima[4],name[10];
int shumu,danjia;
printf("输入产品数量\n");
scanf("%d",&n);
getchar();
for(;i
printf("输入产品代码: ");
scanf("%s",daima);
printf("输入产品名: ");
scanf("%s",name);
printf("输入单价: ");
scanf("%d",&danjia);
printf("输入产品数目: ");
scanf("%d",&shumu);
strcpy(a[i].dm,daima);
strcpy(a[i].mc,name);
a[i].dj = danjia;
a[i].sl = shumu;
a[i].plan();
}
sort(a,a+n);
for(i=0;i
return 0;
}
yiivon@126.com
我的没输出复数的情况;
struct goods{
char dm[4];char mc[10];int dj;int sl;long je;}
struct cj{
char dm[4];char mc[10];int dj;int sl;long je;}
float root(float a,float b,float c,float x1,float x2)
{ float x1,x2,t;
t=b*b-4*a*c;
if(t>0){x1=(-b+sqrt(t))/2.0;2=(-b-sqrt(t))/2.0;}
else if(t==0){x1=-b/2.0;x2=-b/2.0;}
else return;
}
good_sorts(goods g[],int n){
for(int i=0;i
for(int i=0;i
if(g[i].je==g[j].je)
if(strcmp(g[i].dm,g[j].dm)<0){cj tmp=g[i];g[i]=g[j];g[j]=tmp;}
}
}
int main(){
float a,b,c,x1,x2;
int n;goods a[n];
root(a,b,c);
cout<<"1.求方程ax2+b2+c=0的根<
if(choice==1){cout<<"请输入a,b,c"<
if(choice==2){
cout<<"请输入商品个数"<
goods_sorts(a,n);
cout<<"排序后"<
}
不知道这样可符合你的要求,呵呵
难啊