[ create a new paste ] login | about

Link: http://codepad.org/URfJ48UZ    [ raw code | output | fork ]

C, pasted on Apr 26:
// pt có dạng: ax^4 + bx^2 + c = 0
/*
Giải thuật: Đặt ẩn phụ t = x^2 (t >= 0)
=> pt có dạng: at^2 + bt + c = 0

=> biện luận dựa theo t
khi ra 1 nghiệm t thì sẽ có 2 nghiệm x chính là
cộng trừ căn bậc 2 của t
*/
#include <stdio.h>
#include <conio.h>
#include <math.h>

int main()
{
	float a, b, c; // Khai báo.

	printf("\nNhap vao a = ");
	scanf_s("%f", &a);

	printf("\nNhap vao b = ");
	scanf_s("%f", &b);

	printf("\nNhap vao c = ");
	scanf_s("%f", &c);

	if (a == 0) // pt có dạng: bx + c = 0
	{
		if (b == 0) // pt có dạng: c = 0
		{
			if (c == 0)
			{
				printf("\nPhuong trinh co vo so nghiem");
			}
			else  // nếu c khác 0
			{
				printf("\nPhuong trinh vo nghiem");
			}
		}
		else   // Nếu b khác 0
		{
			float t = -c / b;

			if (t < 0)
			{
				printf("\nPhuong trinh vo nghiem");
			}
			else
			{
				float x1 = sqrt(t);
				float x2 = -sqrt(t);

				printf("\nPhuong trinh co 2 nghiem:\nx1 = %f\nx2 = %f", x1, x2);

			}

		}
	}
	else  // Nếu a khác 0
	{
		float Denta = b * b - 4 * a * c;

		if (Denta < 0)
		{
			printf("\nPhuong trinh vo nghiem");
		}
		else if (Denta == 0)
		{
			float t = -b / (2 * a);

			if (t < 0)
			{
				printf("\nPhuong trinh vo nghiem");
			}
			else
			{
				float x1 = sqrt(t);
				float x2 = -sqrt(t);

				printf("\nPhuong trinh co 2 nghiem:\nx1 = %f\nx2 = %f", x1, x2);

			}
		}
		else // Denta > 0
		{
			float t1 = (-b + sqrt(Denta)) / (2 * a);
			float t2 = (-b - sqrt(Denta)) / (2 * a);

			if (t1 >= 0)
			{
				float x1 = sqrt(t1);
				float x2 = -sqrt(t1);

				printf("\nPhuong trinh co nghiem:\nx1 = %f\nx2 = %f", x1, x2);
			}

			if (t2 >= 0)
			{
				float x1 = sqrt(t2);
				float x2 = -sqrt(t2);

				printf("\nPhuong trinh co nghiem:\nx3 = %f\nx4 = %f", x1, x2);
			}

			if (t1 < 0 && t2 < 0)
			{
				printf("\nPhuong trinh vo nghiem");
			}

		}
	}

	_getch();
	return 0;
}


Output:
1
Line 18: error: conio.h: No such file or directory


Create a new paste based on this one


Comments: