-
May 28th, 2012, 10:41 PM
#1
Could someone explain how the below c++ code works....??
Code to determine mode .
double mode (double numbers [], int i)
{
int* Repetition = new int[n];
for (int i = 0; i < n; ++i)
{
Repetition[i] = 0;
int j = 0;
bool bFound = false;
while ((j < i) && (numbers[i] != numbers[j]))
{
if (numbers[i] != numbers[j])
{
++j;
}
}
++(Repetition[j]);
}
int mode = 0;
for (int i = 1; i < n; ++i)
{
if (Repetition[i] > Repetition[mode])
{
mode= i;
}
}
cout << "Mode\t\t\t\t"<< numbers[mode]<<endl<<endl;
return 0;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|