Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute FORTRAN-95 Online

program ex18b
!this program calculates value of y
integer::x,y
read*,x
if (x<3)then
y=-5*x
else
y=6*x**2+1
end if
print*,y
end program ex18b

Compile and Execute FORTRAN-95 Online

program ex18
!this program calculate the value of y
integer ::x,y
read *,x
if (x>2)then
y= -2+3*x
else
y=8+x**2
end if
Print *, y
end program ex18

Calculate the value of y using Fortran

program ex18a
! this program calculate the value of y
integer::x,y
read*, x
if (x>2) then
y = -2+3*x
else
y = 8+x**2
end if 
print*, y
end program ex18a

Vector Product in Fortran

program vectorcalc

implicit none

real(8) a1,a2,a3,b1,b2,b3,c1,c2,c3
real(8), dimension (:), allocatable :: vectorA(:),vectorB(:),vectorCross(:)
integer dim
real(8) :: dot_product


write(*,*)'enter vectorA,B,Cross dimension'
read(*,*) dim
write(*,*)'entered dimension is', dim

allocate( vectorA (dim))
allocate( vectorB (dim))
allocate( vectorCross(dim))

write(*,*)'enter vectorA values'
read(*,*) a1,a2,a3
write(*,*)'enter vectorB values'
read(*,*) b1,b2,b3

vectorA= (/a1,a2,a3/)
vectorB= (/b1,b2,b3/)

if(dim.eq.3) then 

c1=a2*b3-a3*b2
c2=a3*b1-a1*b3
c3=a1*b2-a2*b1

vectorCross=(/c1,c2,c3/)

    write(*,*) 'a x b:', vectorCross

    write(*,*) 'a*b:', dot_product(vectorA,vectorB)
else 
    write(*,*) 'a*b:', dot_product(vectorA,vectorB)
end if


deallocate (vectorA)
deallocate (vectorB)
deallocate (vectorCross)

end program vectorcalc

Do Loop in Fortran

program ex22
integer::i
do i=0,20,10
   Print *, i
   end do
end program ex22

Multiplication and IF Statement in Fortran

program ex20
integer::a,b,c,d
read *, a,b
print *, 'a=' ,a, 'b=',b
if(a<b) then
c=2*a*b
   Print *, '2*product=' ,c
   else
   d=2*(a+b)
   print *, '2 sum=',d
   end if
end program ex20

Bubble Sort using Fortran

PROGRAM  bubbleSort
   implicit  none
  Integer :: row, col, i, ii, iii, temp 
  integer, dimension(:,:), allocatable :: myarray
  
  Allocate(myarray(1:row, 1:col))

DO i =1, row
    READ(1,*) myarray(i, :)
    do ii =1, row-1
        do iii =1, row- i-1
        if (myarray(i,iii)> myarray(i,iii+1)) then 
            temp = myarray(i,iii)
            myarray(i,iii+1) = temp
        end if 
        end do 
    end do 
    
    
END DO


DO i = 1, row
      write(*,*) myarray(i, :)
END DO 

END program bubbleSort

Maximum value of three numbers using Fortran

program j
!maximum value of three numbers
integer::a,b,c
read*,a,b,c
print*,'a=',a
print*,'b=',b
print*,'c=',c
print*,
if (a>b)then
if(a>c)then
max=a
else 
max=c
end if
end if
if(b>c)then 
max=b
else
max=c
end if
print*,'max value of 3 numbers is',max
end program j

Compile and Execute FORTRAN-95 Online

program prob3
!this program between low numbers and high that are divisible by numbers
integer ::n,i,low,high
read *, low,high,n
print *,'low =',low
print *, 'high =', high
do i=low,high
a=mod(i,n)
if (a==0) then
print *, i
end if
end do
end program prob3

test23

program test23
!print all numbers between LOW and HIGH that are divisible by NUMBER
integer::low,high,i,m,n
read*,low,high,n
do i=low,high
m=mod(i,n)
if(m==o)then
print*,i
end if 
end do
end program test23

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.