I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

lucian\′s Photo
27 Oct 06, 7:16AM
(1 reply)
I am now going to explain the logic behind the algorithm and the 101-elements arrays.

So first I read the user data and store it like this: n = the number of marks, marks[] = a dynamically allocated array containing all marks. Now I have declared the freq[] array containing 101 elements, with this rule: freq[k] = the frequency of mark k. I had to use 101 elements since the marks could go from 0 to 100, which total 101 possible marks. By declaring the freq[] array this way

int freq[101] = {0};

all its elements are first assigned a value of 0. What I do next is browse through the marks array and for each of its elements I add up 1 to their corresponding element in the freq[] array. Then I display the marks and their corresponding frequencies by browsing through the freq[] array and only considering the non-zero elements.

Next I declare the pos[] array and assign to each of its elements a value of 0. Again I browse through the marks[] array and for each mark I store its position in the marks[] array into its corresponding element in the pos[] array. There are two possibilities - either it is the first time I store the position for a particular mark, in which case I do not display anything, or it is the second time and therefore I display the difference between the new position and the previously stored position for that mark. I conclude that it is the first time whenever the corresponding element in the pos[] array for that mark is 0, so no position has been assigned to it.

Please let me know if you have further questions on the algorithm or get any more compiler errors.

xboxxerr\′s Photo
9 Feb 15, 11:58AM
in the pos[] array. There are two possibilities - either it is the first time I store the position for a particular mark, in which case I do not display anything, or it is the second time [url=http://www.examsheets.com]70-483[/url]
Currently you need to be logged in to leave a message.