Arrays

I was in hospital and missed all the classes when the prof. lectured about Arrays. Now I'm trying to read the chapter in the book but I'm afraid I don't understand very much. I think if I go ahead and try to do some exercise I'll get to understand the texts better. So here's one exercise in the book that I'm trying to do. It would be a GREAT help if someone can show me how to do such exercise? Thanks very much.

-Some CS retarded-

Write a batch program that analyzes exam scores.

Input

The first line contains a title. The second line holds the number of exams. The remaining lines have ten exam scores per line except the last line, which will have from one to ten exam scores. All exam scores are integers. Your program must work for any title (up to 60 characters) and number of exams (up to 100 integers).

The corresponding output formatted as shown below. Of course, print the values you calculate for the mean rather than question marks. The histogram you print should display a distribution of scores exactly as shown using one star per score. You may assume that no line of output will have more than 50 stars.

An array is basically very simple. Conceptually it's a collection of "boxes" that are all referred to by the same name, plus an index that specifies which box. So a bit like house addresses. If you live on Evergreen Terrace, that's the array name. 742 is the index, as are 740, 738 etc. So a certain well known family might be represented as EvergreenTerrace[742], and their neighdiddlyeighbours are either EvergreenTerrace[740] or EvergreenTerrace[744] (assuming US house numbering works the same way as the UK where one side of the road has all even numbers and the other side all odd numbers).

So going back to C; you can declare a single variable as

Code:

int a;

An array with 10 elements is declared in this way:

Code:

int arr[10];

and this defines 10 memory locations that are addressed as arr[0], arr[1], arr[2],... arr[9]. Note that arr[10] doesn't exist; you get 10 elements numbered 0..9, because C starts counting things at zero.

The power in this comes from the fact that the number can be replaced with a variable. So this code would be very tedious if we couldn't use arrays: