| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2835 人关注过本帖
标题:[我又出题了]解方程
只看楼主 加入收藏
忆楠
Rank: 1
等 级:新手上路
帖 子:721
专家分:0
注 册:2004-7-5
收藏
得分:0 

大家都在这里说笑 没有有做题阿? 郁闷。。。。


点 鼠 标 , 救 饥 民 http://www./
2004-08-23 18:03
乌鸦丘比特
Rank: 1
等 级:新手上路
威 望:2
帖 子:625
专家分:0
注 册:2004-7-19
收藏
得分:0 

对啊,玩笑开够了,

该做题了。

knocker财迷同志,快做啊,不然咒你哦。

要是有好东西我就买你一次,保你不离,哈哈


我喜欢创造,一只扑腾着翅膀向天空飞翔的乌鸦
2004-08-23 19:18
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 

表达式求值的方法很多,也不是很难,我写了只怕是收不到钱。


九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2004-08-23 21:40
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 

我先来一个吧,这个是从正规方法求的最简单的例子,另外还有穷举的办法。

#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; }

代码写得比较冗长,但也算是周到,把可能都写了。

2004-08-23 21:57
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 
啊~~~啊~~~~啊~~~~,你理解错了吧?晕

九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2004-08-23 22:01
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 

题意不是要这样吗?噢~~~sorry,可否说清楚一点。

2004-08-23 22:21
乌鸦丘比特
Rank: 1
等 级:新手上路
威 望:2
帖 子:625
专家分:0
注 册:2004-7-19
收藏
得分:0 

关键是——方程里不一定只有一个常数项,也不一定只又一个X或Y的系数。

live41你的方法好象是建立在已经把XY和常数项化为一个的基础上……

但我输入的是方程,不是每项的系数。


我喜欢创造,一只扑腾着翅膀向天空飞翔的乌鸦
2004-08-24 07:58
AQcdr
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2004-8-22
收藏
得分:0 

我来帮你不过编的不怎么样---我的处子作呀,输入时请依次输入系数请看例子,

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


------------------------------------------------ 阿庆AQcdr
2004-08-24 10:37
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
哦,好的,我下去想想。
2004-08-24 10:37
AQcdr
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2004-8-22
收藏
得分:0 

我来帮你不过编的不怎么样---我的处子作呀,输入时请依次输入系数请看例子,

现在重新作过了,输入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 编的


------------------------------------------------ 阿庆AQcdr
2004-08-24 10:54
快速回复:[我又出题了]解方程
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053971 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved