{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture-05.1

# Lecture-05.1 - Week 5.1 CSE 1540.03#1B Write a program to...

This preview shows pages 1–3. Sign up to view the full content.

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

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

View Full Document
#2A Write a program to input a sequence of positive real numbers and find the largest.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}