FORTRAN 90 L e c

advertisement
FORTRAN 90
Lecturer : Rafel Hekmat Hameed
University of Babylon
Subject : Fortran 90
College of Engineering
Mechanical Engineering Dep.
Year : Second B.Sc
Q /G B
Given a quadratic equation as follows:
ܽ‫ ݔ‬ଶ ൅ ܾ‫ ݔ‬൅ ܿ ൌ Ͳ
if b*b-4*a*c is non-negative, the roots of the equation can be solved with the
following formulae:
”‘‘–ʹ ൌ
ଵ
ଶୟ
”‘‘–ͳ ൌ
൫െ„ െ ξ„ ଶ െ Ͷƒ…൯
ͳ
ቀെ„ ൅ ඥ„ ଶ െ Ͷƒ…ቁ
ʹƒ
Write a program to read in the coefficients a, b and c, and compute and display the
roots. If the discriminate b*b - 4*a*c is negative, the equation has complex root.
Thus, this program should solve the equation if the discriminate is non-negative and
show a message otherwise. Use select case-statement.
program quadratic_equation
implicit none
real:: a,b,c,d,root,root1,root2
read(*,*) a,b,c
d=b*B-(4*a*c)
WRITE(*,*)"D=",D
SELECT CASE (INT(D).GE.0)
CASE(.TRUE.)
IF(D==0)THEN
root=-b/(2*a)
write(*,*) root
ϭ
ELSE
root1=(-b+sqrt(d))/(2*A)
root2=(-b-sqrt(d))/(2*A)
write(*,50) root1,root2
50 format(2x,"first root =",2x,f9.6,/,2x,"second root =",2x,f9.6)
endif
CASE (.FALSE.)
WRITE(*,*) "THERE IS NO SOLUTION"
END SELECT
end
Q/GB
Write a fortran 90 program to print and sum all the numbers between 100 and
1000 that divided by 15 without any reminder, the program will terminated if the
summation of the numbers is greater than 650. Use format statement to print your
result.
PROGRAM DIVIDE
IMPLICIT NONE
INTEGER::I,SUM
DO I=100,1000,1
IF (MOD(I,15)==0)THEN
WRITE(*,10) I
10 FORMAT(2X,I4)
SUM=SUM+I
ENDIF
IF(SUM.GT.650)EXIT
ENDDO
WRITE(*,8) SUM
8 FORMAT(2X,"SUMMATION OF NUMBERS=",I8) ; END
Ϯ
Download