CSE 1540.03
Week 4.1
January 23, 2012
Problems
#1.
Write a program to input a sequence of positive numbers and compute
the average.
#2.
Write a program to input a sequence of numbers and compute the
average.
#3.
Change #1 and #2 to find the largest number in the sequence.
#4.
Change the problems to input
n
followed by
n
numbers.
#5.
Write a program to compute
x
e

.
Solutions
#1.
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
CSE 1540
Week 4.1 – January 23, 2012
page 1 of 2
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Stream processing paradigm
Program reads a sequence of data items, each data item is processed
and discarded before the next data item is read and processed.
Program is independent of the size of the data to be processed.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Winter '12
 HOFBAUER
 Addition, Negative and nonnegative numbers, Natural number, data item

Click to edit the document details