Lecture-05.1 - CSE 1540.03 Week 5.1 January 30, 2012...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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*, "Enter the next number (end with neg. num.)" read*, x if (x .lt. 0.0) exit sum = sum + x count = count + 1 end do print*, "Average = ", 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*, "Enter the next number (end with 1e-38)" read*, x if (x .eq. 1e-38) exit sum = sum + x count = count + 1 end do print*, "Average = ", sum/count end test data: general case: 7.5 2 -12.6 4.3 1e-38 boundary case #1: 2.5 1e-38 boundary case #2: 1e-38 problem with boundary case #2: divide by zero if (count .eq. 0) then print*, "list of numbers is empty" else print*, "Average = ", 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.

Page1 / 4

Lecture-05.1 - CSE 1540.03 Week 5.1 January 30, 2012...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online