You are on page 1of 2

Lab 6

1. Write a program to calculate the average of n numbers, and then compute the deviation
of each number about the average

Sample output:
How many numbers will be average? 5
i=1 x=3
i=1 x = -2
i=1 x = 12
i=1 x = 4.4
i=1 x = 3.5

The average is 4.18

i=1 x = 3.00 d = -1.18


i=2 x = -2.00 d = -6.18
i=3 x = 12.00 d = 7.82
i=4 x = 4.40 d = 0.22
i=5 x = 3.50 d = -0.68

2.Write a short program that prints the number of days per month.

Sample output:

Month 1 has 31 days.


Month 2 has 28 days.
Month 3 has 31 days.
Month 4 has 30 days.
Month 5 has 31 days.
Month 6 has 30 days.
Month 7 has 31 days.
Month 8 has 31 days.
Month 9 has 30 days.
Month 10 has 31 days.
Month 11 has 30 days.
Month 12 has 31 days.

3.Suppose we took a telephone survey to discover how people felt about a particular
television show and we asked each respondent to rate the show on a scale from 1 to 10,
inclusive .One of the first pieces of data we would like to gather is a table showing the
distribution of the ratings. In other words, we would like to know how many people rated
the show a1, how many a 2 and so on up to 10.Write the program for the survey as well.

Sample output:
Enter your response
6
5
8
3
9
6
5
7
15
Bad response: 15
5
5
1
7
4
10
5
5
6
8
9
6

Rating Number of Response


____ ____________

1 1
2 0
3 1
4 1
5 6
6 4
7 2
8 2
9 2
10 1

You might also like