FORTRAN 90

advertisement
FORTRAN 90
Lecturer : Rafel Hekmat Hameed
University of Babylon
Subject : Fortran 90
College of Engineering
Year : Second B.Sc.
Mechanical Engineering Dep.
Q
Qϭϭ //G
GAA
Write a fortran 90 program to calculate sin(x) from the following series
šଷ šହ š଻
•‹ሺšሻ ൌ š െ ൅ െ ൅ ‫ڮ‬
͵Ǩ ͷǨ ͹Ǩ
The program will terminate if the absolute value of term is less than tolerance say
1e-6 . [Input the value of ࢞ by degree]. Use format statement to print your result.
program sin_series
implicit none
real,parameter:: pi=3.141592, error=1e-5
integer::i,j,f
real::sum , term , x
read(*,*)x
x=(x*pi)/180
i=1
do
f=1
do j=1,i
f=f*j
;
enddo
term=(-1)**(i/2)*x**i/f
if(abs(term).lt.error)exit
sum=sum+term
ϭ
i=i+2
enddo
x=(x*180)/pi
write(*,50) x,sum
50 format(2x,"sin(",f5.2,")=",1x,f9.6)
end
Q
QϮϮ //G
GAA
Write afortran90 program to read all positive three digits integer numbers
which its middle digits is less than other two digits. Use format statement to print
your result.
program digit
implicit none
integer::i,l1,l2,l3
do i=100,999
l1=i/100
l2=i/10-l1*10
l3=i-l1*100-l2*10
if(l1.gt.l2.and.l3.gt.l2)then
write(*,5) i
5 format (2x,i4)
endif
enddo
end
Ϯ
Q
Qϭϭ //G
GBB
Write a program in Fortran 90 to find the value of ( Z ) from series bellow:
‫ ݖ‬ൌͳെ
ሺ‫ ݔ‬െ ͳሻଶ ሺ‫ ݔ‬െ ʹሻସ ሺ‫ ݔ‬െ ͵ሻ଺
൅
െ
൅‫ڮ‬
͵Ǩ
ͷǨ
͹Ǩ
The program will be terminated if the absolute value of term is less than tolerance
say 1e-6.
program series
implicit none
real,parameter::error=1e-6
real::term,sum=1,x
integer::i,j,f
read(*,*)x
i=1
do
f=1
do j=1,(2*i+1)
f=f*j
enddo
term=(-1)**i*(x-i)**(2*i)/f
if(abs(term)<error)exit
sum=sum+term
i=i+1
enddo
write(*,56)sum
56 format(1x,"z=",1x,e15.10)
End
ϯ
Q
QϮϮ //G
GBB
Write afortran90 program to read all positive three digits integer numbers
which its middle digits equal the summation of square other digits. Print your result
in output file.
Ex: 390 , 251 , 240 , ….
program digit1
implicit none
integer::i,l1,l2,l3
open(unit=3,file="xx.dat")
do i=100,999
l1=i/100
l2=i/10-l1*10
l3=i-l1*100-l2*10
if(l2==l1**2+l3**2)then
write(3,5)i
5 format (2x,i4)
endif
enddo
end
Out put
110
121
152
240
251
282
390
ϰ
Download