用fortran写一个小程序,计算平面上任意两点a(xa,ya),b(xb,yb)间的距离
1个回答
展开全部
program square
type :: Point2d
real :: x
real :: y
end type
type(Point2d) :: a, b
read '(f10.4, f10.4)', a
read '(f10.4, f10.4)', b
print *, distance(a,b)
contains
real function distance(this, other)
type(Point2d),intent(in) :: this, other
distance = sqrt((a%x-b%x)**2 + (a%y-b%y)**2)
end function
end program
type :: Point2d
real :: x
real :: y
end type
type(Point2d) :: a, b
read '(f10.4, f10.4)', a
read '(f10.4, f10.4)', b
print *, distance(a,b)
contains
real function distance(this, other)
type(Point2d),intent(in) :: this, other
distance = sqrt((a%x-b%x)**2 + (a%y-b%y)**2)
end function
end program
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询