Created
September 16, 2009 15:55
-
-
Save shelling/188117 to your computer and use it in GitHub Desktop.
Equation Set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* Question: | |
** write a program to solve equation set | |
** ax + by = 1 | |
** cx + dy = 2 | |
** and print the result | |
*/ | |
int main(void) | |
{ | |
double a,b,c,d,e,x,y; | |
printf("enter the a,b,c,d in fomula\na: "); | |
scanf("%lf",&a); | |
printf("b: "); | |
scanf("%lf",&b); | |
printf("c: "); | |
scanf("%lf",&c); | |
printf("d: "); | |
scanf("%lf",&d); | |
e=a*d-b*c; | |
x=(d-2.0*b)/e; | |
y=(2.0*a-c)/e; | |
if(a/c==b/d) | |
{ | |
if(a/c==0.5) /* it should be 0.5 rather than 1/2, because a/c is float */ | |
{ | |
printf("infinite answer"); | |
} | |
else | |
{ | |
printf("no answer"); | |
} | |
} | |
else | |
{ | |
printf("x,y=%f,%f",x,y); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment