Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as C++ by registered user xujiayu ( 4 years ago )
#include <stdio.h>
#include <conio.h>
#include <math.h>

/*
GIAI PHUONG TRINH BAC 2 BANG HAM-THU TUC
ax^2 + bx + c = 0 

TH1:
+ a = 0
    =>luc nay  pt co dang : bx + c = 0 
	=> chinh la phuong trinh bac 1 
	=> goi lai ham pt bac 1 
	th2:
a != 0 => tinh delta roi bien luan */

void nhapdulieu (double &x)
{
	 printf ("\nHay nhap so : ");
	 scanf("%lf",&x);
}
void giaiphuongtrinhbac1 (double a , double b)
{
	 if (a == 0)
	 {  
		 if(b == 0)
		 {
		    printf("\nPt vo so nghiem");
		 }
		 else
		 {
			 printf("\nPT vo nghiem");
		 }
	 
	 }
	 else
	 {
		 double x = -b/a;
		 printf("\nPT co nghiem x = %lf",x);
	 }
}
void giaiphuongtrinhbac2(double a , double b,double c)
{
	if(a == 0)
	{
	  giaiphuongtrinhbac1(b,c); //o day ta co b chinh la a cua bai bac 1 tren , c chinh la b 
	}
	else
	{// tinh delta
		double denta = b * b - 4 * a * c;
		if (denta < 0 )
		{
		   printf("\nPT vo nghiem");
		}
		else if (denta == 0)
		{
		   double x = -b / (2 * a);
		   printf("\nPT co nghiem kep x1 = x2 = %lf",x);
		}
		else
		{
			double x1 = (-b + sqrt(denta)) / (2 * a);
			double x2 = (-b - sqrt(denta)) / (2 * a);
			printf("\nPT co 2 nghiem phan biet : \nx1 = %lf \nx2 = %lf",x1,x2);
		}

	}
}
int main()
{     
	 double a, b ,c;

	 nhapdulieu(a);
	 nhapdulieu(b);
	 nhapdulieu(c);

	 giaiphuongtrinhbac2( a, b,c);

	getch();
	return 0;



}

 

Revise this Paste

Your Name: Code Language: