謝謝 劉耀仁 黃科智 提供以下程式 Home
如有問題 請在本網站之討論室 發言討論
read *,a,b,c
print *,’max=’,amax1(a,b,c)
print *,’min=’,amin1(a,b,c)
stop
end
real foot,inch,dfoot
integer a
print *,’1.for foot and inch to foot’
print *,’2.for foot to foot and foot’
read *,a
if (a.eq.1)then
read *,foot,inch
dfoot=foot+inch/12.0
print *,foot,’foot and’,inch,’inch=’,dfoot,’foot’
else if(a.eq.2)then
read *,doot
foot=int(dfoot)
inch=(dfoot-foot)*12.0
print *,doot,’foot=’,foot,’foot and’,inch,’inch’
else
print *,’you did not key in correctly!’
end if
stop
end
real a,degree,f,c
print *,’1 for c to f,2 for to c’
print *,’please key in 1 or 2’
read *,a,degree
if (a.eq.1)then
c=degree
f=(c*9/5)+32
end if
if (a.eq.2) then
f=degree
c=(f-32)*5/9
end if
print *,f,’degree f=’c,’degree c’
stop
end
--------------------------------------------------------
print *,’please key in numbers to run root’
read *,a,b,c
if (a .eq. 0)then
print *,’please key in a not equal to 0’
read *,a
end if
if (b**2-4*a*c .lt. 0)then
print *,’d can not lt 0’
stop
end if
if (b**2-4*a*c .ge. 0)then
root1=(-b+sqrt(b**2+4*a*c))/(2*a)
root2=(-b-sqrt(b**2-4*a*c))/(2*a)
end if
print *,root1
print *,root2
print *,’if d<0 no real sol’
stop
end
real a,b,c,root1,root2
print *,’please key in a,b,c for a quadratic equation’
read *,a,b,c
disk=b**2-4.0*a*c
if(a .eq. 0)then
root1=(-c/b)
print *,’equation is not quadratic’
print *,’the singleral root is,root1’
else if(disk .gt. 0)then
root1=(-b+sqrt(disk))/(2.0*a)
root2=(-b-sqrt(disk))/(2.0*a)
print *,’there are two real roots’
print *,’the root1 is’,root1
print *,’the root2 is’,root2
else if(disk.eq.0)then
root1=-b/(2.0*a)
print *,’there is only real root’
print *,’the root is’,root1
else if(disk.lt.0)then
e=-b/(2.0*a)
p=sqrt(abs(disk))/(2.0*a)
print *,’there are two imaginary roots’
print *,’the root1 is’,e,’+’,p,’i’
print *,’the root2 is’,e,’-‘,p,’i’
end if
stop
end
PRINT *,’PLEASE KEY IN A,B,C FOR A*X**2+B*X+C=0’
READ *,A,B,C
IF(A .EQ. 0)THEN
PRINT *,’SORRY,A CAN NOT BE ZERO’
PRINT *,’PLEASE KEY IN A,B,C AGAIN’
READ *,A,B,C
END IF
D=B**2-4*A*C
IF(D.GE.0)THEN
ANS1=(-B+SQRT(D))/(2*A)
ANS2=(-B-SQRT(D))/(2*A)
PRINT *,’ANSWER 1=’,ANS1
PRINT *,’ANSWER 2=’,ANS2
END IF
IF(D .LT. 0)THEN
E = (SQRT(-D))/(2*A)
realp= -B/(2*A)
PRINT *,’ANSWER 1=’, realp,’+’,E,’*I’
PRINT *,’ANSWER 2=’, realp,’-‘,E,’*I’
END IF
STOP
END
real a
print *,’please key in a number’
print *,’this number is the PH of solution’
read *, a
if (a.ge.12) then
print *,’the solution is very alkaline’
else if ((a.gt.7).and.(a.lt.12)) then
print *,’the solution is alkaline’
else if((a.eq.7)then
print *,’the solution is neutral’
else if ((a.gt.2) .and. (a.lt.7)) then
print *,’the solution is acidic’
else
print *,’the solution is very acidic’
end if
stop
end
real a, b, c, d, p
print *,’please key four numbers’
print *,’p is the smallest of four numbers’
read *, a,b,c,d
p = amin1(a,b,c,d)
print *,’p=’,p
stop
end