MSC321 Homework 1: Understanding Fortran Programming Concepts, Assignments of Earth Sciences

A homework assignment for a fortran programming course. It includes exercises on the difference between comments, variable declarations, and executable statements, as well as calculations using fortran expressions and the factorial function.

Typology: Assignments

Pre 2010

Uploaded on 08/30/2009

koofers-user-eys-1
koofers-user-eys-1 🇺🇸

5

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MSC321 Homework 1
1. Explain the difference between comments, variable declaration and executable
statements.
2. What values are expected from the following operations
(a) (2.0 + 3.0**2) / (8.0-2.0+1.0)
(b) (2.0+3.0)**2 / (8.0-2.0+1.0)
(c) 3.0/5.0 + 2.0 ** 3
(d) 3/5 + 2**3
3. what value do you expect to print after reading this program?
program test
implicit none
real :: x=3.0
integer :: i=7
x = x/(x-1.0)**2**(-1)-1.0
i = i + 1/i-3
print *, x,i
stop
end program test
4. If nis declared as an integer, what do you expect the following statement to
print:
m = n - (n/2)*2
5. Write a FORTRAN expression to evaluate the function
f=1.0 + cos2x
(1.0 + x3)(1 x2)
6. Write a code to print out the value of the expression f=1+tanh(x0.5)
2at 101
equally spaced point between -5 and 5.
1
pf2

Partial preview of the text

Download MSC321 Homework 1: Understanding Fortran Programming Concepts and more Assignments Earth Sciences in PDF only on Docsity!

MSC321 Homework 1

  1. Explain the difference between comments, variable declaration and executable statements.
  2. What values are expected from the following operations

(a) (2.0 + 3.02) / (8.0-2.0+1.0) (b) (2.0+3.0)2 / (8.0-2.0+1.0) (c) 3.0/5.0 + 2.0 ** 3 (d) 3/5 + 2**

  1. what value do you expect to print after reading this program?

program test implicit none real :: x=3. integer :: i= x = x/(x-1.0)2(-1)-1. i = i + 1/i- print *, x,i stop end program test

  1. If n is declared as an integer, what do you expect the following statement to print:

m = n - (n/2)*

  1. Write a FORTRAN expression to evaluate the function

f =

1 .0 + cos^2 x (1.0 + x^3 )(1 − x^2 )

  1. Write a code to print out the value of the expression f = 1+tanh( 2 x −^0 .5)at 101 equally spaced point between -5 and 5.
  1. Explain in word the logic behind the following code

program factorial implicit none integer :: x, fct integer, parameter :: cutoff = 100

do read *, x if (x < 0) then exit elseif (x<cutoff) then fct = 1 do i = 1,x fct = fct * i enddo print *,fct else print *,’Number too big’ endif enddo

stop program factorial

Hints Be careful about interpreting the types of constants, and remember that integer division is chopped. You need not write actual code and run them, but feel free to do so if you want to make sure of your answers. You need not hand in the programs.