i want you to help me to find the mode in array size n
if there two element have same number of repetion there is no mode .
mode :: the most number is repeted .
e.g
{1,2,3,4,3}
the mode is 3
but if we have {1,2,3,1,3}
there is no mode because 3=1 with number of reption .
my code have two function
first is to sort the array and other function to chick if there a mode or not ..

#include <iostream.h>
void bubble_sort(int Array[ ],int  ,int   );
 void main()
{int n_elements,temp=0,Array[50];
	cout<<"How many elements ? ";
	cin>>n_elements;
	cout<<"Enter the elements:-\n";
	for(int i=0;i<n_elements;i++) 
	   cin>>Array[i];
bubble_sort(Array,n_elements,temp);	
 }
void bubble_sort(int Array[],int n_elements,int temp)
{ 
		for(int i=0;i<n_elements;i++)
		{
			for(int j=0;j<n_elements;j++)
			{
				if (Array [i]<Array[j]){
				temp=Array[i];
				Array[i]=Array[j];
				Array[j]=temp;
			}
		}
	}
	for( i=0;i<n_elements;i++)
		cout<<Array[i]<<"  ";}
 }

how i can write function to chick .??

Given this sorted array
1,2,4,4,4,5,6,7,7,8,8
what steps would you take to find the mean sitting at your desk with pencil and paper. Write those steps down. What steps can easily be converted into code? Which ones can't? Those that can't need to be broken down into more steps.

Post what you have and we can help you fine tune it.

for (int i=0;i<n_elements;i++)	
{		temp = 0;		
compare = numbers[i]; 	
	for (int j=0;j<n_elements;j++)	
	{		
	if (numbers[j] == compare)		
	{			

	temp++;			}	
	} 		
if (temp > qMax)		
{			
max = compare;			
qMax = temp;	
else if ( max=temp)cout << "there is no mode ";
	}	} 	
cout<<"The most repeating number: "<<max<<endl;
	system("PAUSE"); 	return 0;

Edited 5 Years Ago by programing: n/a

This article has been dead for over six months. Start a new discussion instead.