ユーマちゃんのブログ

質問・要望はTwitterもしくはコメントで。返信はTwitterで。

Programming Example 7 (訂正版)

!This program was change on November 18.

 

 

program report7
  implicit none
  real:: b
  integer:: a,c,i,j,k,N,t=0
  logical judge

  print*, "Enter the limit of hypotenuse"
  read(*,*) N
  print*, "The following numbers are all primitive Pythagorean triples with hypotenuse no longer than",N

  do i= 2,N
    c = i
    do j = 1, N
      a = j
      b = sqrt(real(c**2-a**2))
      if (b==real(int(b)) .and. b/=0 .and. real(a)<=b ) then
        judge = .true.
        do k =2,int(b)
          if (mod(a,k)==0 .and. mod(int(b),k)==0) then
            judge = .false.
          end if
        end do
        if ( judge ) then
          t = t + 1
          print*, t,")",a,int(b),c
        end if
      end if
    end do
  end do
  print*, "The total number of primitive Pythagorean triplese is",t
end program report7