1st degree equation in C

1

How can I implement a algorithm that calculates a 1st degree equation in C ?

I know that a first-degree equation to be solved must follow three steps:

  

1 °: Group the numbers on one side of = all terms you have   the incognito (x) and add on the other side all the terms that do not have   ( x ). In order to carry out this transposition, the signals that go   each number should be changed. So what is adding on one side   passes to the other to subtract and vice versa, and what is multiplying   from one side it passes to the other to divide.

     

Example: 4x + 1 = 2x + 7

     

Transposition: 4x - 2x = 7 - 1

     

2 °: Resolve operations separately on each side of the   equal. That is, to solve the first degree equation must solve   the operations until leaving a number on each side of equal.

     

Result: 2x = 6

     

3 °: Finally, to solve the equation of the first degree the number that   this is multiplying by the x happens to divide to the other side of the signal   of equal, in our case:

     

x = 6/2

     

Final result: x = 3

Implementation followed by @Rafael Carneiro de Moraes's response:

#include <stdio.h>

int main(void)
{
    float x, a, b, c;

    b = 1 + 7;

    a = 4 + 2;

    c = a + b;

    x = (c - b) / a;

    printf("\nx = %f",x);

    return 0;
}

I do not know if the result is correct.

    
asked by anonymous 10.10.2015 / 04:54

1 answer

2

Considering an equation of type ax + b = c , where:

  • ax : the sum of all x of the equation
  • b : the sum of all the numbers in the equation
  • c : the result

And supposing your program will get the values of a , b and c , the equation you need for is x = (c - b) / a .

If you have more than one x you need to test if / else to calculate a , because if it is 0 there is no equation but a possible equality of and c .

    
10.10.2015 / 05:18