program arithmeticOp ! this program performs arithmetic calculation implicit none ! variable declaration integer :: a, b, c ! assigning values a = 5 b = 3 ! Exponentiation c = a ** b ! output print *, "c = ", c ! Multiplication c = a * b ! output print *, "c = ", c ! Division c = a / b ! output print *, "c = ", c ! Addition c = a + b ! output print *, "c = ", c ! Subtraction c = a - b ! output print *, "c = ", c end program arithmeticOp
program gravitationalDisp ! this program calculates vertical motion under gravity implicit none ! gravitational acceleration real, parameter :: g = 9.81 ! variable declaration real :: s ! displacement real :: t ! time real :: u ! initial speed ! assigning values t = 5.0 u = 50 ! displacement s = u * t - g * (t**2) / 2 ! output print *, "Time = ", t print *, 'Displacement = ',s end program gravitationalDisp
program variableTesting implicit none ! declaring variables integer :: total real :: average complex :: cx logical :: done character(len=80) :: message ! a string of 80 characters !assigning values total = 20000 average = 1666.67 done = .true. message = "A big Hello from Tutorials Point" cx = (3.0, 5.0) ! cx = 3.0 + 5.0i Print *, total Print *, average Print *, cx Print *, done Print *, message end program variableTesting
program division implicit none ! Define real variables real :: p, q, realRes ! Define integer variables integer :: i, j, intRes ! Assigning values p = 2.0 q = 3.0 i = 2 j = 3 ! floating point division realRes = p/q intRes = i/j print *, realRes print *, intRes end program division
program testingInt implicit none !two byte integer integer(kind = 2) :: shortval !four byte integer integer(kind = 4) :: longval !eight byte integer integer(kind = 8) :: verylongval !sixteen byte integer integer(kind = 16) :: veryverylongval !default integer integer :: defval print *, huge(shortval) print *, huge(longval) print *, huge(verylongval) print *, huge(veryverylongval) print *, huge(defval) end program testingInt
program testingInt implicit none integer :: largeval print *, huge(largeval) end program testingInt
program addNumbers ! This simple program adds two numbers implicit none ! Type declarations real :: a, b, result ! Executable statements a = 12.0 b = 15.0 result = a + b print *, 'The total is ', result end program addNumbers
module integration_library implicit none contains function calculatex (x) double precision :: calculatex double precision, intent (in) :: x calculatex = x **4 * log(x + (x**2 + 1)**0.5 ) end function function area (y1,y2,dx) double precision :: area double precision, intent (in) :: y1,y2,dx area = ((y1 + y2) * dx) / 2.0 end function end module integration_library program integration use integration_library, only:calculatex,area implicit none double precision :: a,b,r,y1,y2,dx integer :: i,n 10 format(a,1x,f20.10) read (*,*) a read (*,*) b read (*,*) n dx = (b-a) / n r = 0 do i=1,n y1 = calculatex (a + ((i-1) * dx)) y2 = calculatex (a + (i * dx)) r = r + area(y1,y2,dx) end do write(*,10) 'area =', r end program
program external_function implicit none double precision :: x,myexp read(*,*) x 10 format(a,1x,f6.2,a,1x,f20.10) 20 format(a,1x,f20.10) write(*,10) ' exp(',x,') =',exp(x) write(*,10) ' myexpval(',x,') =',myexp(x) write(*,20) ' difference =',exp(x) - myexp(x) end program external_function function myexp(x) double precision,intent(in) :: x double precision :: myexp,e,nfact integer :: i,n n = 12 e = 0 nfact = 1 do i = 0,n if (i > 1) nfact = nfact * i e = e + ((x ** i) / nfact) end do myexp = e end function myexp
program Datos !Programado por Luis Angel Carmona Ontiveros, tremendo ídolo de ídolos implicit none integer tam, i, j, temp, opcion integer, allocatable, dimension(:) :: num print *,"Inserta la cantidad de numeros a usar" read(*, "(i2)") tam allocate (num(tam)) do while (opcion /= 4) print *,"Ordenador:" print *,"1.- Ingresar valores" print *,"2.- Ordenar de Menor a Mayor" print *,"3.- Ordenar de Mayor a Menor" print *,"4.- Salir del programa" read(*, "(i1)") opcion select case (opcion) case(1) print *,"Ingrese los numeros:" do i=1,tam read(*, "(i3)") num(i) end do case(2) do i=1,tam do j=i+1,tam if(num(i)>num(j)) then temp = num(i) num(i) = num(j) num(j) = temp endif end do end do print *,"Lista ordenada Menor a Mayor:" do i=1,tam print *, num(i) end do case(3) do i=1,tam do j=i+1,tam if(num(i)<num(j)) then temp = num(i) num(i) = num(j) num(j) = temp endif end do end do print *,"Lista ordenada Mayor a Menor" do i=1,tam print *, num(i) end do end select end do deallocate(num) end program Datos
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more