大家都在这里说笑 没有有做题阿? 郁闷。。。。
点 鼠 标 , 救 饥 民 http://www./
我先来一个吧,这个是从正规方法求的最简单的例子,另外还有穷举的办法。
#include<iostream.h>
void main() { int a[3],b[2],s[3],x,y; cout<<"input 1st:"<<endl; cin>>a[0]>>b[0]>>s[0]; cout<<"input 2nd:"<<endl; cin>>a[1]>>b[1]>>s[1];
if((a[0]==0&&a[1]==0)||(b[0]==0&&b[1]==0)) //无解的情况 cout<<"error!"<<endl;
else //讨论其中有一个系数为0的情况,分四种 { if(a[0]==0&&a[1]!=0) { y=s[0]/b[0]; x=(s[1]-y*b[1])/a[1]; } if(a[1]==0&&a[0]!=0) { y=s[1]/b[1]; x=(s[0]-y*b[0])/a[0]; } if(b[0]==0&&b[1]!=0) { x=s[0]/a[0]; y=(s[1]-x*a[1])/b[1]; } if(b[1]==0&&b[0]!=0) { x=s[1]/a[1]; y=(s[0]-x*a[0])/b[0]; } }
if((b[0]<0&&b[1]<0)||(b[0]>0&&b[1]>0)) //一般情况 { a[2]=a[0]*b[1]-a[1]*b[0]; s[2]=s[0]*b[1]-s[1]*b[0]; x=s[2]/a[2]; y=(s[1]-a[1]*x)/b[1]; }
cout<<"x="<<x<<" "<<"y="<<y<<endl; }
代码写得比较冗长,但也算是周到,把可能都写了。
我来帮你不过编的不怎么样---我的处子作呀,输入时请依次输入系数请看例子,
aX+bY=c 2X+3Y=5
dX+eY=f 6X+4Y=4
依次输入a b c d e f 以空格隔开随后回车,此题即输入2 3 5 6 4 4
小数负数都可以,分数没试过应该没问题,输出只会是整数或小数。
#include <conio.h> /* 此头函数请不要删除 */ #include <stdio.h> #include <math.h> void main() { float a,b,c,d,e,f,X,Y,r1,r2; printf(" AQ MATH--Equation 1.1\nI am too sad to sleep so I make this programme.\nPlease in put the number a b c d e f and press the enter.\n"); scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f); if((a==d)&&(b==e)) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&b!=0&&d!=0&&c!=0) {Y=c/b; X=(f-Y*e)/d; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(b==0&&a!=0&&d!=0&&e!=0) {X=c/a; Y=(f-d*X)/e; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(d==0&&a!=0&&b!=0&&e!=0) {Y=f/e; X=(c-b*Y)/a; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(e==0&&a!=0&&b!=0&&d!=0) {X=f/d; Y=(c-a*X)/b; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&b==0&&d!=0&&e!=0) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");} else if(d==0&&e==0&&a!=0&&b!=0) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&d==0&&b!=0&&e!=0) {if((c/b)==(f/e)) {Y=c/b; printf("The answer is:\n"); printf("X is any number\n"); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if((c/b)!=(f/e)) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");}} else if(b==0&&e==0&&a!=0&&d!=0) {if((c/a)==(f/d)) {X=c/a; printf("The answer is:\n"); printf("Y is any number\n"); printf("X=%f\n",X); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if((c/a)!=(f/d)) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");}} else if(a==0&&e==0&&d!=0&&b!=0) {X=f/d; Y=c/b; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(b==0&&d==0&&a!=0&&e!=0) {X=c/a; Y=f/e; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&b==0&&d==0) {Y=f/e; printf("The answer is:\n"); printf("X is any number\n"); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&d==0&&e==0) {Y=c/b; printf("The answer is:\n"); printf("X is any number\n"); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(b==0&&d==0&&e==0) {X=c/a; printf("The answer is:\n"); printf("Y is any number\n"); printf("X=%f",X); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&b==0&&e==0) {X=f/d; printf("The answer is:\n"); printf("Y is any number\n"); printf("X=%f",X); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(a!=0&&b!=0&&d!=0&&e!=0) {if(a==b&&d==e) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");} else {Y=(c*d-f*a)/(b*d-e*a); X=(c-Y*b)/a; r1=a*X+b*Y; r2=d*X+e*Y; if(r1==c&&r2==f) {printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");}}} getch(); /* 此语句请不要删除*/ }
我用的是Turbo C for windows 4.5,想获得exe文件把邮箱告诉我
此题计算很简单,不过无解的情况较多所以对我这只菜鸟有些烦
---AQcdr
我来帮你不过编的不怎么样---我的处子作呀,输入时请依次输入系数请看例子,
现在重新作过了,输入aX+bY=c,dX+eY=f然后回车即可
分数不可用
#include <conio.h> /* 此头函数请不要删除 */ #include <stdio.h> #include <math.h> void main() { float a,b,c,d,e,f,X,Y,r1,r2; printf(" AQ MATH--Equation 1.1\nI am too sad to sleep so I make this programme.\nPlease in put the number a b c d e f and press the enter.\n"); scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f); if((a==d)&&(b==e)) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&b!=0&&d!=0&&c!=0) {Y=c/b; X=(f-Y*e)/d; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(b==0&&a!=0&&d!=0&&e!=0) {X=c/a; Y=(f-d*X)/e; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(d==0&&a!=0&&b!=0&&e!=0) {Y=f/e; X=(c-b*Y)/a; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(e==0&&a!=0&&b!=0&&d!=0) {X=f/d; Y=(c-a*X)/b; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&b==0&&d!=0&&e!=0) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");} else if(d==0&&e==0&&a!=0&&b!=0) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&d==0&&b!=0&&e!=0) {if((c/b)==(f/e)) {Y=c/b; printf("The answer is:\n"); printf("X is any number\n"); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if((c/b)!=(f/e)) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");}} else if(b==0&&e==0&&a!=0&&d!=0) {if((c/a)==(f/d)) {X=c/a; printf("The answer is:\n"); printf("Y is any number\n"); printf("X=%f\n",X); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if((c/a)!=(f/d)) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");}} else if(a==0&&e==0&&d!=0&&b!=0) {X=f/d; Y=c/b; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(b==0&&d==0&&a!=0&&e!=0) {X=c/a; Y=f/e; printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&b==0&&d==0) {Y=f/e; printf("The answer is:\n"); printf("X is any number\n"); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&d==0&&e==0) {Y=c/b; printf("The answer is:\n"); printf("X is any number\n"); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(b==0&&d==0&&e==0) {X=c/a; printf("The answer is:\n"); printf("Y is any number\n"); printf("X=%f",X); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(a==0&&b==0&&e==0) {X=f/d; printf("The answer is:\n"); printf("Y is any number\n"); printf("X=%f",X); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else if(a!=0&&b!=0&&d!=0&&e!=0) {if(a==b&&d==e) {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");} else {Y=(c*d-f*a)/(b*d-e*a); X=(c-Y*b)/a; r1=a*X+b*Y; r2=d*X+e*Y; if(r1==c&&r2==f) {printf("The answer is:\n"); printf("X=%f\n",X); printf("Y=%f\n",Y); printf("Thank you use my programme.\nPress enter to exit this programme.\n");} else {printf("It is no ansmer.\nThank you use my programme.\nPress enter to exit this programme.\n");}}} getch(); /* 此语句请不要删除*/ }
我使TurboCwindows4.5 编的