Consider a program which stores the frequency of marks of student in a...
For this purpose, we can ignore the below forty numbers and have an array of 60 index to store the individual frequencies from 40 to 100.
View all questions of this test
Consider a program which stores the frequency of marks of student in a...
Explanation:
The best way to store the frequency of marks above 40 for 500 students is to use an array of 60 numbers. Here's why:
1. Range of marks: The marks range from 0 to 100, but we only want to record the frequency of marks above 40. So, we need an array that can hold values in the range [41...100].
2. Number of students: There are 500 students, so we need an array that has 500 elements.
3. Frequency of marks above 40: We only want to store the frequency of marks above 40, so we don't need to store the frequency of marks between 0 and 40.
4. Number of elements in the array: To store the frequency of marks above 40 for 500 students, we need an array that has 60 elements. The reason is that there are 60 possible values of marks above 40, which are [41, 42, 43, ..., 99, 100]. So, each element of the array corresponds to one possible value of marks above 40.
5. Example: Suppose we have the following data for 5 students:
- Student 1: 35 (failed)
- Student 2: 45 (passed)
- Student 3: 80 (passed)
- Student 4: 60 (passed)
- Student 5: 95 (passed)
We only need to record the frequency of marks above 40, so we don't care about the marks of Student 1. For the other 4 students, we need to increment the frequency of the corresponding element in the array. Here's how the array would look like after processing the above data:
- [ 0, 1, 0, 0, ..., 0, 1, 1, 1, ..., 1, 1 ] (an array of 60 numbers)
The first element represents the frequency of marks 41, the second element represents the frequency of marks 42, and so on, until the last element represents the frequency of marks 100.