c   3.$BFs<!J}Dx<0(B ax**2 + bx + c = 0 $B$N2r(B 
c     $B?9@nLwBg(B , 22980138
c
      program ex3
      implicit none
c
      integer:: i,j
      real(4):: a1,b1,c1,x1e,x2e,e(2),k(2)
      real(8):: a2,b2,c2,x1d,x2d
      
      do i=1,2
       if (i==1) then
          write(6,*)'(1)'
       else if (i==2) then
          write(6,*)'(2)'
       end if
       do j=1,2
c-----(a)$B$N?tCM$rBeF~(B
        if (j==1) then
 
         a1= 2.718282e0
         b1=-6.844566e2
         c1= 3.161592e-1
         a2= 2.718282d0
         b2=-6.844566d2
         c2= 3.161592d-1

         write(6,*)'(a)'
 
c-----(b)$B$N?tCM$rBeF~(B
        else if (j==2) then
         
         a1= 2.718282e0
         b1=-1.854089e0
         c1= 3.161592e-1
         a2= 2.718282d0
         b2=-1.854089d0
         c2= 3.161592d-1       
         
         write(6,*)'(b)'
        end if
c--(1)$B$NJ}K!$G2r$$$?C1@:EY!"G\@:EY(B
        if (i==1) then
         call tannseido(a1,b1,c1,x1e,x2e)
         call baiseido(a2,b2,c2,x1d,x2d)
c--(2)$B$NJ}K!$G2r$$$?C1@:EY!"G\@:EY(B
        else if (i==2) then
         call yukou(a1,b1,c1,x1e,x2e)     
         call baiseido(a2,b2,c2,x1d,x2d)
        end if
c-----$B@dBP8m:9(B
        e(1)=abs(x1e-x1d)
        e(2)=abs(x2e-x2d)
c-----$BAjBP8m:9(B      
        k(1)=e(1)/x1d
        k(2)=e(2)/x2d
      
        write(6,*) '$BC1@:EY$G$N7k2L(B'
        write(6,*) 'x1 =',x1e
        write(6,*) 'x2 =',x2e
        write(6,*) '$BG\@:EY$G$N7k2L(B'
        write(6,*) 'x1 =',x1d
        write(6,*) 'x2 =',x2d
        write(6,*) 'x1$B$N@dBP8m:9(B',e(1)
        write(6,*) 'x2$B$N@dBP8m:9(B',e(2)
        write(6,*) 'x1$B$NAjBP8m:9(B',k(1)
        write(6,*) 'x2$B$NAjBP8m:9(B',k(2)
      
       enddo 
      enddo
      stop
      end

c-----$BC1@:EY$N%5%V%k!<%A%s(B 
      subroutine tannseido(a1,b1,c1,x1e,x2e)
      implicit none
      real(4),intent(in) :: a1,b1,c1
      real(4),intent(out):: x1e,x2e
      real(4)::d1
c      
      d1=b1**2-4.0e0*a1*c1
      x1e=(-b1+sqrt(abs(d1)))/(2.0e0*a1)
      x2e=(-b1-sqrt(abs(d1)))/(2.0e0*a1)
c      
      return
      end

c-----$BG\@:EY$N%5%V%k!<%A%s(B
      subroutine baiseido(a2,b2,c2,x1d,x2d)
      implicit none
      real(8),intent(in) :: a2,b2,c2
      real(8),intent(out):: x1d,x2d
      real(8)::d2
c      
      d2=b2**2-4.0e0*a2*c2
      x1d=(-b2+sqrt(abs(d2)))/(2.0e0*a2)
      x2d=(-b2-sqrt(abs(d2)))/(2.0e0*a2)
c      
      return
      end

c-----(2)$B$N%5%V%k!<%A%s(B
      subroutine yukou(a1,b1,c1,x1e,x2e)
      implicit none
      real(4),intent(in) :: a1,b1,c1
      real(4),intent(out):: x1e,x2e
      real(4)::d1

      d1=b1**2-4.0e0*a1*c1
        
        if (b1 >= 0.0e0) then
          x1e=(-b1-sqrt(abs(d1)))/(2.0e0*a1)
          x2e=c1/(a1*x1e)
        else if (b1 < 0.0e0) then
          x1e=(-b1+sqrt(abs(d1)))/(2.0e0*a1)
          x2e=c1/(a1*x1e)
        end if
      
      return
      end
      
      
