Fortran 90 Programmes
Fortran 90 Programmes
do
z=x+y
read*,x,y print*,x+y
enddo print*,"addition of two number is",z end
Page 1 [C:\fortran\compare3.f90]
!programe to find the largest among three number
real :: a,b,c
print*,"enter the three number"
read*,a,b,c
if (a>=b) then
if (a>=c) then
print*, "largest number is",a
else print*, "largest number is",c
endif else
if (b>=c) then
print*,"largest number is",b
else print*, "largest number is",c endif endif
end
Page 1 [C:\fortran\ascending_order.f90]
!programe to arrange ascending order of numbers
Do j=1,n
Do i=1,j-1 if (A(i)>A(i+1)) then
temp=A(i) A(i)=A(i+1)
A(i+1)=temp
endif enddo enddo
program descending_order
implicit none
integer::i,n,j,temp,A(100)
Do j=n,2,-1
Do i=1,j-1 if (A(i)<A(i+1)) then
temp=A(i+1) A(i+1)=A(i)
A(i)=temp endif
enddo
enddo
program primes
implicit none
integer :: Range,Optimusprime
integer :: divisor
Range = 100
program primes
implicit none
Range = 100
do prime = 3, Range, 2
divisor = 3 do if(divisor*divisor>prime .or. mod(prime,divisor)==0)exit
divisor =divisor + 2
enddo
if(divisor*divisor>prime) then
print*, prime
endif
enddo
end
Page 1 [C:\fortran\matrix_addition.f90]
!programme for matrix addition
program matrix_addition
implicit none
print*,"enter the no. of rows and columns of matrix A & B" read*,m,n print*,"enter
the elements of matrix A"
do i =1,m
read*, (a(i,j),j=1,n)
enddo print*,"enter the elements of matrix B"
do i=1,m
read*,(b(i,j),j=1,n)
enddo print*,"the sum of two matrix is"
do i=1,m do
j=1,n
c(i,j)=a(i,j)+b(i,j) enddo
enddo
do i=1,m
print*,(c(i,j),j=1,n)
enddo end program
matrix_addition
Page 1 [C:\fortran\matrix_multiplication.f90]
!programe to find matrix multiplication
program matrix_multiplication
implicit none
integer::i,j,m,n,k,l,A(100,100),B(100,100),C(100,100)
Do i=1,n
Do j=1,m read*,A(i,j)
enddo
enddo
print*,"Enter the numbers of colums of second matrix" read*,l print*,"enter the
elements of second matrix"
Do i=1,m
Do j=1,l read*,B(i,j)
enddo
enddo
do i=1,n do
j=1,l c(i,j)=0
do k=1,m c(i,j)=c(i,j)+A(i,k)*b(k,j)
enddo enddo
enddo
do i=1,n print*,(C(i,j),j=1,l)
enddo end
Page 1 [C:\fortran\factorial.f90]
!programme of factorial
program factorial
implicit none
print*,"give the no n" read*,n if (n < 0) error stop "factorial is singular for negative integers"
fact = 1.0
do i = 2, n
fact = fact * i
enddo print*,"factorial of n",fact end
program factorial
Page 1 [C:\fortran\fibonacci.f90]
!programme for genarate fibonacci series
program Fibonacci
implicit none
integer :: x,y,temp,ix
x=0 y=1
print*,x print*,y
do ix = 1,45,1
temp=x+y x=y
y=temp
print*,temp
enddo end
program fibonacci
Page 1 [C:\fortran\bisection.f90]
!Bisection fuction
Program bisection_function
implicit none
print*,"enter two guess values and the max iteration on you prefer" read*,a,b print*,a,b
value" else
do
itr=itr+1 c=(a+b)/2
if(f(a)*f(c)<0)then
r=(b-c)/c
g=abs(r) b=c
else
if(f(c)*f(b)<0)then
r=(a-c)/c a=c
endif
if(g<r)then
print*,"c is root"
print*,"value of function at c",f(c) print*,"no. of iteration",i
exit
endif endif enddo
endif
end program bisection_function
!function subprogram
function f(x) real ::
f real :: x
Page 2 [C:\fortran\bisection.f90]
f=2*x-2 end
function f
Page 1 [C:\fortran\newton.f90]
program newton_raphson_method
implicit none
program matrix_addition
implicit none
do i=1,100 f0=f(x0)
f1=f(x1)
f=x*3+3*x*x-3*x+1 endfunction
Page 1 [C:\fortran\falsi.f90]
program falseposition
implicit none
n=0 ka=0
kb=0 fc = f(fa)
fd = f(fb)
fa = x fc =
f(fa) ka = 0 kb
= kb+1
if (kb .ge. 2) then
fd = 0.5*fd
end if
else
fb = x fd =
f(fb) kb = 0 ka
= ka+1
if (ka .ge. 2) then fc =
0.5*fc end if
end if xa = (fa*fd-fb*fc)/(fd-fc) if (abs(f(xa)-
n = n+1
end do end program
falseposition
program least_square
implicit none
integer :: j,i,del,slope
real :: x,y,a,sumx,sumy,sumxy,sumxx,sumyy,c(100),d(100)
open(unit=10,file="data-1.txt")
do i=1,j read(10,*) c(i),d(i)
enddo
sumx =0
sumy =0
sumxy =0
sumxx =0
sumyy=0 do
i=1,j
print*,slope print*,"intercept",a
end program least_square
Page 1 [C:\fortran\trapozidal.f90]
program trapezoid
implicit none
print*, "The EXACT Value Of The Integral Is", exA e = abs ((approxA -
exA))/approxA
! FUNCTION DECLARATION
x**5 + x**3
end function g
Page 1 [C:\fortran\simpson.f90]
program simpson
implicit none
h = (b - a)/n s1 =
0.0 s2 = 0.0 m =
n/2
do i = 1, m
do l = (n - 2)/2
do i = 1, l
print*, "The APPROXIMATE Value Of The INTEGRAL Is", approxA expA = g(b) -
g(a)
x f = x**5 + x**3
return
Page 2 [C:\fortran\simpson.f90]