League quadratic equation 2 ax² + bx + c = 0

Hello everyone, at all before we have solved superlative equation already, this article we are going to solve the equation Career 2 nhé.

Threads: League quadratic equation 2: ax² + bx + c = 0 (a ≠ 0) with a, b, c input from the keyboard

We recall knowledge of the quadratic equation 2 with a ≠ 0 as follows:

B1: calculate delta: D = b ^ 2 – 4ac
B2: Check delta for each case from easy to difficult
TH1: D < 0 => The equation has no solution.
TH2: D = 0 => The equation has dual experience x = \frac{-b}{2a}
TH3: D> 0 => Equation 2 experience x = \frac{-b\pm \sqrt{\Delta }}{2a}

From here we will gradually know how, It stands as the steps we do. In this 1 the problem is how to calculate the square root 2?. You can view the article in your links, but that is purely algorithmic, C gives us the library math.h to calculate the square root 2 command sqrt(x) – calculate square roots 2 the number x, then. Now only the code alone.

/*
*	Giai phuong trinh bac 2: ax² + bx + c = 0
*/

#include <stdio.h>
#include <math.h>

int main() {
	float a, b, c;
	float delta;

	printf("Enter a, b and c:\n");
	scanf("%f%f%f", &a, &b, &c);

	delta = b * b - 4 * a * c;

	if(a == 0) {
		printf("You must enter a > 0\n");
		return 0; // finish 
	}

	if(delta < 0) {
		printf("Impossible equation (No result for x)\n");
	} 

	if(delta == 0) {
		float x = -b / (2 * a);
		printf("x = %.2f\n", x);
	}

	if(delta > 0) {
		float x1 = (-b + sqrt(delta) ) / (2 * a);
		float x2 = (-b - sqrt(delta) ) / (2 * a);
		printf("x1 = %.2f\n", x1);
		printf("x2 = %.2f\n", x2);
	}

	return 0;
}
Exercise: You take the quadratic equation 2 such conditions may enter a = 0