1
How can I implement a algorithm calculating an equation of 1° grade in C?
I know that a first-degree equation to be solved must follow three steps:
1°: Group the numbers on one side of the = all terms that have the unknown (x) and gather on the other side all terms that do not have (x). To make this transposition, the signals ahead of each number must be changed. So, what is adding up on one side passes to the other subtracting and vice versa, and what is multiplying on one side passes to the other to divide.
Example: 4x + 1= 2x + 7
Transposing: 4x - 2x = 7 - 1
2°: Resolve operations separately on each side of the signal from equal. That is, to solve the first-degree equation must solve operations until a number on each side of the same.
Upshot: 2x = 6
3°: Finally, to solve the first-degree equation the number that this multiplying by x now divides to the other side of the sign of equal, in our case:
x = 6 / 2
Final result: x = 3
Implementation followed by @Rafael Carneiro de Moraes' reply:
#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 don’t know if the result is correct.
What you’ve already done?
– Felipe Avelar
I am trying to implement the above example, but I am not able to define a logic of how to represent these steps in programming.
– gato
You don’t have to declare
c
asa + b
because the result will go wrong. I will use your example (4x + 1= 2x + 7): joining the equal sides would be 2x = 6 and the value of its x should be 3. That is, in that case you should do:b = 1; 
a = 4 - 2;
c = 7;
x = (c - b) / a;
– Rafael Carneiro de Moraes
I implemented here, the result was 3.
– gato