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.