1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| #include <math.h>
#include <stdio.h>
#define PI 3.14159265
int main()
{
/*Introducing variables*/
float param_a,param_b,param_c,param_d,param_e,param_f;
float index_x,index_y;
float check,result;
scanf("%f %f %f",¶m_a,¶m_b,¶m_c);
scanf("%f %f %f",¶m_d,¶m_e,¶m_f);
printf("%f %f %f\n",param_a,param_b,param_c);
printf("%f %f %f\n",param_d,param_e,param_f);
/* Check help me to knom if the solution is single, infini or doesn't exist */
check=(param_a*param_e)-(param_b*param_d);
if ( check=!0 )
{ /* Single solution */
index_x=(param_e*param_c)-(param_b*param_f);
index_x=index_x/((param_e*param_a)-(param_b*param_d));
index_y=(param_f-(param_d*index_x))/param_e;
if ( (int)index_x==index_x )
printf("Result: The equations have a single solution: x=%.f y=%.3f\n",index_x,index_y);
else if ( (int)index_y==index_y )
printf("Result: The equations have a single solution: x=%.3f y=%.f\n",index_x,index_y);
else if ( ((int)index_x==index_x) && ((int)index_y==index_y) )
printf("Result: The equations have a single solution: x=%.f y=%.f\n",index_x,index_y);
}
else if ( (param_a==param_d) && (param_b==param_e) && (param_c!=param_f) )
{
printf("Result: The equations have no solution\n");
}
else if ( (param_a==param_d) && (param_b!=param_e) && (param_c==param_f) )
printf("Result: The equations have no solution\n");
else if ( (param_a!=param_d) && (param_b==param_e) && (param_c==param_f) )
printf("Result: The equations have no solution\n");
else if ( (param_a==0) && (param_b==0) && (param_c!=0) )
printf("Error: Triplet #1 does not represents coefficient of a line.\n");
else if ( (param_d==0) && (param_e==0) && (param_f!=0) )
printf("Error: Triplet #2 does not represents coefficient of a line.\n");
else printf("Erreur..\n");
return 0;
} |
Partager