linear equations problem

Oct 8, 2009 at 7:25am
(algebra:solving linear equations) You can use Cramer's rule to solve the following 2*2 system of linear equation:

a*x+b*y=e
c*x+d*y=f

x=e*d-b*f/a*d-b*c
y=a*f-e*c/a*d-b*c

write a program that prompts the user to enter a, b, c, d, e, and f. and display the result. if ad-bc is 0, report that "The equation has no solution."

there was what i written

....dubugging...thx!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main ()    
{
	double x;
    double y;
   	double a,b,c,d,e,f;
    cout << "Enter a, b, c, d, e, f: "; // Ask the user to enter the 6 numbers
    cin >> a >> b >> c >> d >> e >> f ; // enter the numbers
         
	if (a*d-b*c == 0)
	{
		cout << " The equation has no solution." << endl;
	}
    else
    { 
	    x = (e*d-b*f)/(a*d-b*c); 
        y = (a*f-e*c)/(a*d-b*c);
	   cout << " x is: " <<  x <<"and y is: " << y <<  endl;
    }
	return 0;
}
Last edited on Oct 8, 2009 at 7:33am
Oct 8, 2009 at 11:57am
Ugh.

Must you use floating point?

The likelihood of your if statement being true is extremely small due to floating point roundoff error.
Oct 8, 2009 at 1:42pm
Are you sure you should manually be typing the values for e and f?
Oct 9, 2009 at 2:59pm
More complicated liner equations can be solved by Guass method.
For details please visit the website: http://hi.baidu.com/eryar/blog/item/138debc45c2560cf38db4983.html
Topic archived. No new replies allowed.