	program phuongPhapChiaDoi 
		real ss, ssn, a, b ,c 
		i = 0
!ss la sai so yeu cau 
!ssn la sai so tam thoi
!a, b la khoang nghiem 
!c la chia doi a, b 
     2		print *, 'Nhap vao khoang nghiem a, b' 
		read *, a, b 
		if (F(a)*F(b) > 0.or.a==b) goto 2 !kiem tra a, b
     4		print *, 'Nhap vao khoang sai so' 
		read *, ss 
		if (ss <= 0) goto 4 !kiem tra sai so nhap vao 
		print 6
     6		format (' Bat dau: ', /)
!phuong phap chia doi
	     	c = (a+b)/2 
     3	      	x = c 
		i = i + 1

		if (f(c) == 0) then
			print *, 'nghiem cua phuong trinh la ', c
			stop
		end if 
		
		if (f(c)*f(a) < 0) then !rut ngan khoang nghiem
			b = c
		else if (f(c)*f(b) < 0) then 
			a = c 
		end if 
	 	
		c = (a + b)/2
		ssn = abs(x - c) !tinh sai so hien tai 

		print 5, i, c, ssn
     5		format ('Lap lan thu ', i2, ': x = ', f10.8, ' sai so: ', E14.7, /)
		if (ssn <= ss) then !kiem tra sai so 
			print *, 'Ket thuc!'
			stop 
		end if 
		goto 3 
		
	contains 
		function F(x) !ham can tinh 
			real F, x 
			F = 3*x*x - 4*x - 2 
		end function 
	end 	
