Superlative solving equations ax + b = 0

Threads: Superlative solving equations ax + b = 0 (other a 0) With the coefficients a, b is entered from the keyboard.

To solve this, you recall the mathematical knowledge we have learned of the ordinary.
Due to a different 0 so we always experience x = -b/a. So easy and, formula has, only now just code.

/*
*	Giai Phuong trinh ax + b = 0
*/

#include <stdio.h>

int main() {
	float a, b;
	printf("Enter a and b: ");
	scanf("%f%f", &a, &b);

	if(a == 0) {
		printf("You must enter a <> 0 !\n");
	} else {
		printf("Result: x = %.2f\n", -b/a);
	}

	return 0;
}

Simple as that. However, now we try to upgrade more 1 little if allowed enter a = 0 so what?

Threads: Superlative solving equations ax + b = 0 (a can of 0) With the coefficients a, b is entered from the keyboard.

So we need to recall, if a = 0 the equation becomes b = 0. If b = 0 the equations become 0 = 0, always right so the equation is true for all x. If other b 0, Meanwhile equation has no solution. So just use if else examine the cases a little more done.

/*
*	Giai Phuong trinh ax + b = 0
*/

#include <stdio.h>

int main() {
	float a, b;
	printf("Enter a and b: ");
	scanf("%f%f", &a, &b);

	if(a == 0) {
		if(b == 0) {
			printf("True with all x\n");
		} else {
			printf("Impossible equation (No result for x)\n");
		}


	} else {
		printf("Result: x = %.2f\n", -b/a);
	}

	return 0;
}