QUESTION 1:
SOLUTION
1 sum_temp = 0: sum_hours = 0
2 for count = 1 to 365 do
3 input temp, hours
4 sum_temp = sum_temp + temp
5 sum_hours = sum_hours + hours
6 next
7 mean_temp = sum_temp/365
8 mean_hours = sum_hours/365
9 print mean_temp, mean_hours
QUESTION 2:
SOLUTION
1 tallest = 0
2 shortest = 500
3 for count = 1 to 500 do
4 input height
5 if height > tallest then tallest = height
6 if height < smallest then smallest = height
7 next
8 print tallest, shortest
A geography class decide to measure daily temperatures and hours of sunshine per day over a 12 month period (365 days)
Write an algorithm, using pseudocode, which inputs the temperatures and hours of sunshine for all 365 days, and finally outputs the average (mean) temperature for the year and the average (mean) number of hours per day over the year.
SOLUTION
1 sum_temp = 0: sum_hours = 0
2 for count = 1 to 365 do
3 input temp, hours
4 sum_temp = sum_temp + temp
5 sum_hours = sum_hours + hours
6 next
7 mean_temp = sum_temp/365
8 mean_hours = sum_hours/365
9 print mean_temp, mean_hours
QUESTION 2:
As part of an experiment, a school measured the heights (in metres) of all its 500 students.
Write an algorithm, using pseudocode, which inputs the heights of all 500 students and outputs the height of the tallest person and the shortest person in the school.
SOLUTION
1 tallest = 0
2 shortest = 500
3 for count = 1 to 500 do
4 input height
5 if height > tallest then tallest = height
6 if height < smallest then smallest = height
7 next
8 print tallest, shortest
No comments:
Post a Comment