- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
Software programming learning aide
CS50 threads to aide as a supplementary resource › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 3: [Algorithms] – Linear Search, Binary Search, Bubble Sort, Selection Sort, Recursion, Merge Sort › How i, j and voter, rank differ in dimension despite of integer data type
Although int i and int j as well int voter and int rank are all integer data type, there is a dimensional difference between first two (int i and int j) and last two (int voter and int rank).
It should be because voter and rank are getting values based on two for loops involving i and j. So we can call voter and rank as two dimensional arrays. Although no where could I see voter and rank defined as arrays! It is int preferences that includes voter and rank:
// preferences[j] is jth preference for voter i int preferences[MAX_VOTERS][MAX_CANDIDATES];
Initially, when I tried to use printf (line 141), I did not expect two dimensional values (01,02,03…), given voter defined as int type (missed my attention that arrays too can be of int type).
printf(“voter no.: %i”, voter);
So while on first look, it appeared to me that i,j and voter, rank are synonymous, they are not.
While int preferences by definition two dimensional, interesting to see how voter and rank too are getting transformed as two dimensional by application of for loops (involving i and j).
Note: The reason I have posted is if anyone can correct or add to what I observed.
Reply
https://edstem.org/us/courses/176/discussion/2260175?comment=5163337[learn_press_profile]