Finding average of a two dimensional array

I did some problem based on two dimensional array. I'm not quite happy with the code I've produced. Could someone tell me if there's a better way of doing this stuff? The problem demands the use of one/two dimensional arrays.

Problem Statement:
1. Read a bunch of temperature readings. ie, A latitude and a corresponding temperature value (both are ints). Latitude to be from -90 to 90.
2. I need to find the average of the temperature at a particular latitude
3. Print the average temperature for all latitudes from -90 to 90 if present, else "NO DATA"

Below is my code.

Any comments are welcome.

Thanks,
Tina

P.S: Could you tell me how to close a thread? I do not find a close thread option and I did the FAQS too. Perhaps I missed it. Let me know. Thanks again!

I felt having array indices like arr[abs(*p)][0] is not appropriate. And the overall logic, I believe is not good. It does produce correct results and run in reasonable time. I've two arrays because the first one scans the latitude and temperature values and the second one has the temperature sum and their count values at their respective latitude index. Perhaps, I could have two simple integer variables like latitude and temperature while scanf and store them in one two dimensional array in main. Also, to store latitude values -90 to -1, I've used array ranges 1 to 90 and for 1 to 90 I've used 90 to 180. Is there any other way to do this?

Oh I see, sorry it's not a duplicate. Still seems unnecessary to me though, although the benefit of this is that you only have to parse the data once. Still, at only 180 values, unless you're programming a ZX81 or something, scanning through that 180 times is still going to take a few milliseconds at the worst. Is it necessary to store intermediate data, and if so why?

> I felt having array indices like arr[abs(*p)][0] is not appropriate

You need to explain comments like this. Why don't you feel that is appropriate? If that's not appropriate, what would be, and why didn't you code it that way in the first place?

> And the overall logic, I believe is not good

Again, why exactly? What logic would be good? Statements like this make no sense if they are not explained.

> Also, to store latitude values -90 to -1, I've used array ranges 1 to 90 and for 1 to 90 I've used 90 to 180. Is there any other way to do this?

Well, you could create a values array (let's call it v_arr) from 0 to 181 and an integer pointer to the midpoint, i.e. int *i_ptr=&v_arr[90]; Then you can use the values -90 to +90 as indices into i_ptr, thus treating it as if it were defined as int i_ptr[-90...+90], which is a sort of C/Pascal hybrid definition and otherwise impossible in C. Negative indices are perfectly OK in C, as long as the resulting address points to valid memory. It's essentially the same thing. Or you could simply add 90 to the latitude values and store data in v_arr[lat+90] which again more or less amounts to the same thing. Using negative indices will make anyone reviewing your code think twice, check carefully and deduce that you must be smarter than they originally thought, but only IF you've done it right!

Umm..If having arr[lat+90] is not a bad way of doing things, then it's alright.

> I felt having array indices like arr[abs(*p)][0] is not appropriate
You need to explain comments like this. Why don't you feel that is appropriate? If that's not appropriate, what would be, and why didn't you code it that way in the first place?

ANSWER: I thought its inappropriate because of the hard coding of the array indices (column value). I did try for ways to get rid of implanting the column index but I couldn't succeed. So, I followed this option.

> And the overall logic, I believe is not good
Again, why exactly? What logic would be good? Statements like this make no sense if they are not explained.

ANSWER: By this, again I meant the same explanation as above and also using two 2D arrays. I mean finding the average of 1D array is straightforward. So, for two 2D array, I wanted to know if there are any key techniques to do the same.

> printf("0 is not a valid latitude\n");
Why is zero not a valid latitude? What is the latitude of the equator?http://en.wikipedia.org/wiki/Latitude seems to suggest the equator's latitude is 0.

ANSWER: I skipped through latitude 0 because it was not mentioned in the problem statement. No particular reason for that.