- This is a C language program
- The following program is about calculate the the solutions for the linear system:
a1x+b1y=c1,a2x+b2y+c2
. - I checked the syntax of else-if,but the compiler still tells me “Else without a previous if",I got no idea what's happening.
I wonder whether you could give some instructions.
Thanks a lot!
#include<stdio.h>
#include<math.h>
//this program is used to calculate the solutions for the linear system: a1x+b1y=c1,a2x+b2y+c2//
int main()
{
float a1,a2,b1,b2,c1,c2,x,y;
printf("Enter values for a1,a2,b1,b2,c1,c2:");
scanf("%f %f %f %f %f %f",&a1,&a2,&b1,&b2,&c1,&c2);
if ((a1*b2-a2*b1) <= 0.01 || (a1*b2-a2*b1) == 0);//if the denominator is too small//
{
printf("The denominator is 0.\n");
}
else
{
x = (b2*c1-b1*c2)/(a1*b2-a2*b1);
y = (a1*c2-a2*c1)/(a1*b2-a2*b1);
}
printf("x = %f",x);printf("y = %f\n",y);
return 0;
}