ITU Faculty of Aeronautics and Astronautics 01.06.2016

ITU Faculty of Aeronautics and Astronautics 01.06.2016

<p>ITU Faculty of Aeronautics and Astronautics 01.06.2016 Department of Aeronautical Engineering 2015-2016 Fall Term 21949 DNK201E Introduction to Scientific and Engineering Computing (FORTRAN) Final Exam – SOLUTION</p><p>PROBLEM 1: (10p) Find the result of the following expressions.</p><p>(a) 1 / 2 * 0.0 (f) 3 ** 1 / 2 (b) 3.0 / 4 / 5 (g) (1 / 2) **3 (c) 2**1**3 (h) int(Log(10.0)) (d) 1 / 2**0.0 (i) exp(3 / 2.0) (e) 2.0 – 2.0 + 1 (j) "abc"(2:2)//"-"//"123"(2:2)</p><p>SOLUTION 1:</p><p>(a) 0.0 (f) 1 (b) 0.15 (g) 0 (c) 2 (h) 2 (d) 1.0 (i) 4.481689 (e) 1.0 (j) b-2</p><p>PROBLEM 2: (20p) What will be the output of each print statement in the following program? program problem_2 integer, dimension(2,3) :: a = reshape((/1,4,2,5,3,6/), (/2,3/)) integer, dimension(10) :: b = (/(i**2-i+1, i = 1, 10)/) integer :: i print "(3i3)", a(1,1:3), a(2,1:3) print "(2i3)", (a(1:2,i), i = 1,3) print "(4i3)", b(1:10:3) print "(5i3)", b(9:1:-2) end program problem_2</p><p>SOLUTION 2:</p><p>1 2 3 4 5 6 1 4 2 5 3 6 1 13 43 91 73 43 21 7 1</p><p>PROBLEM 3: (20p) The following program will exactly print ten lines. Write the output of the program. program problem_3 character(len=1), dimension(6) :: arr = (/"x", "t", "b", "z", "a", "k"/) character(len=1) :: temp integer :: i, j, n n = size(arr) do i = 1, n do j = i + 1, n if (arr(i)>arr(j)) then temp = arr(i) arr(i) = arr(j) arr(j) = temp print * , arr end if end do end do end program problem_3</p><p>SOLUTION 3: txbzak bxtzak axtzbk atxzbk abxztk abtzxk abkzxt abkxzt abktzx abktxz</p><p>PROBLEM 4: (20p) In the following code Jacobi iteration is applied for finding the root of the equation . The iteration converges when the criterion is satisfied. What will be displayed when the code is executed. program problem4 real :: x1, x2, eps = 0.01, root x1 = .75 do x2 = cos(x1) print *, x2 if (abs(x2-x1)<eps) then root = x2 exit end if x1 = x2 end do print *, "root of equation x - cos(x) = 0 is:", root end program problem4</p><p>SOLUTION 4:</p><p>7.316889E-01 7.440471E-01 7.357336E-01 root of equation x - cos(x) = 0 is: 7.357336E-01</p><p>PROBLEM 5: (30p) A file named ‘scientists.dat’ contains the names of 100 scientists, each on a seperate line as shown in the figure below.</p><p>Isaac Newton Nikola Tesla Albert Einstein ...... Blaise Pascal</p><p>Write a single program that will read the records from this file (a) and save them to a new file called ‘namesort.dat’ sorted in alphabetical order according to names of the scientists, (b) sort the data according to surnames and save the data to a new file ‘surnamesort.dat’.</p><p>SOLUTION 5: program problem5 character(len=10), dimension(4) :: name, surname character(len=10) :: temp integer :: i, j open(10, file = "scientists.dat", status = "old", position = "rewind", action = "read", access = "sequential") do i = 1, 4 read(10,fmt = *) name(i), surname(i) end do do i = 1, 4 do j = i+1, 4 if (name(i)>name(j)) then temp = name(i) name(i) = name(j) name(j) = temp</p><p> temp = surname(i) surname(i) = surname(j) surname(j) = temp end if end do end do open(20, file = "namesort.dat", status = "unknown", position = "rewind", action = "write", access = "sequential") write(20, fmt = "(2a)") (name(i), surname(i), i =1,4) do i = 1, 4 do j = i+1, 4 if (surname(i)>surname(j)) then temp = name(i) name(i) = name(j) name(j) = temp</p><p> temp = surname(i) surname(i) = surname(j) surname(j) = temp end if end do end do open(30, file = "surnamesort.dat", status = "unknown", position = "rewind", action = "write", access = "sequential") write(30, fmt = "(2a)") (name(i), surname(i), i =1,4) end program problem5</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us