From: sam <as...@ya...> - 2011-06-17 09:57:04
|
Sorry it has been a while since I program. It is a stupid question. So, please forgive my ignorance. Maybe I lose my memory or something!! I have a problem with the below code!!! I can’t understand this part: ++frequency [ responses [ answer ] ]; I know this part increment 1 to the value position of the result of this one responses [ answer ] For example responses [ answer ]= 1; then ++frequency [1] But how did the result of frequency[ rating ]= 2,2,2,2,5,11,5,7,1,3 ????? So can you please explain it to me? ////////////////////////////////////////////////////// #include <stdio.h> #define RESPONSE_SIZE 40 #define FREQUENCY_SIZE 11 int main() { int answer, rating, frequency[ FREQUENCY_SIZE ] = { 0 }; int responses[ RESPONSE_SIZE ] = { 1, 2, 6, 4, 8, 5, 9, 7, 8, 10, 1, 6, 3, 8, 6, 10, 3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7, 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10 }; for ( answer = 0; answer <= RESPONSE_SIZE - 1; answer++ ) ++frequency [ responses [ answer ] ]; printf( "%s%17s\n", "Rating", "Frequency" ); for ( rating = 1; rating <= FREQUENCY_SIZE - 1; rating++ ) printf( "%6d%17d\n", rating, frequency[ rating ] ); getchar(); return 0;} ////////////////////// |