This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CSE 1540.03 Week 5.1 January 30, 2012 Problems #1A. Write a program to input a sequence of positive real numbers and compute the average. program oneA implicit none integer count real sum, x sum = 0.0 count = 0 do print*, &quot;Enter the next number (end with neg. num.)&quot; read*, x if (x .lt. 0.0) exit sum = sum + x count = count + 1 end do print*, &quot;Average = &quot;, sum/count end test data: general case: 7.5 2 12.6 4.3 1 boundary case #1: 2.5 1 boundary case #2:1 #1B Write a program to input a sequence of real numbers and compute the average. program oneB implicit none integer count real sum, x sum = 0.0 count = 0 do print*, &quot;Enter the next number (end with 1e38)&quot; read*, x if (x .eq. 1e38) exit sum = sum + x count = count + 1 end do print*, &quot;Average = &quot;, sum/count end test data: general case: 7.5 2 12.6 4.3 1e38 boundary case #1: 2.5 1e38 boundary case #2: 1e38 problem with boundary case #2: divide by zero if (count .eq. 0) then print*, &quot;list of numbers is empty&quot; else print*, &quot;Average = &quot;, sum/count end if CSE 1540 Week 5.1 January 30, 2012 page 1 of 4 #2A...
View
Full
Document
This note was uploaded on 02/13/2012 for the course CSE 1540 taught by Professor Hofbauer during the Winter '12 term at York University.
 Winter '12
 HOFBAUER

Click to edit the document details