Question: Write a function to find out the repeating number with the longest count with array. You can use the below code and fill the code

Write a function to find out the repeating number with the longest count with array. You can use the below code and fill the code for the function "computeLongestSequence" . Output is as follow: Longest repeating number is:1 with count:1 Longest repeating number is:3 with count:4 Longest repeating number is:3 with count:4 Longest repeating number is:3 with count:10

The above statements will be written inside the function "computeLongestSequence" .

The first line could have the number 1 or some other number also depending on your code as the first array has all different elements.

#include using namespace std ; /* The function "computeLongestSequence" prints the longest sequence of a repeating number. If there is more than 1 repeating sequence then any number can be the answer. The function should print the following for each invocation of the array and size. Longest repeating number is: ( repeating number) with count ( count of the number) */ void computeLongestSequence( int arrayOfNumbers[] , int size ) { } int main() { /* int arr5[] = {1 , 2 , 3, 3 }; computeLongestSequence( arr5 , 4 ) ; exit(0); */ const int SIZE=10 ; int arr1[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } ; int arr2[10] = { 1, 2, 3, 3, 3, 3, 7, 7, 9, 10 } ; int arr3[10] = { 2, 2, 3, 4, 5, 6, 3, 3, 3, 3 } ; int arr4[10] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } ; computeLongestSequence( arr1 , SIZE ) ; computeLongestSequence( arr2 , SIZE ) ; computeLongestSequence( arr3 , SIZE ) ; computeLongestSequence( arr4 , SIZE ) ; return(0) ; }

You can use the initial code in "main" function to debug your application.

This is my program. Please fix it for me. Per my teacher, I can use just one loop only . Therefore, thank you for fixing this program and the output has to be be above .

#include

using namespace std ;

int main()

{

const int SIZE=10 ;

int arr1[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } ;

int arr2[10] = { 1, 2, 3, 3, 3, 3, 7, 7, 9, 10 } ;

int arr3[10] = { 2, 2, 3, 4, 5, 6, 3, 3, 3, 3 } ;

int arr4[10] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } ;

computeLongestSequence( arr1 , SIZE ) ;

computeLongestSequence( arr2 , SIZE ) ;

computeLongestSequence( arr3 , SIZE ) ;

computeLongestSequence( arr4 , SIZE ) ;

return 0 ;

}

void computeLongestSequence( int arrayNumbers[] , int size )

{

int currentNo=arr1[0] , currentCount = 1;

int maxCount = 0; maxNo =0;

for ( int i1 = 1; i1 < 6; i1 ++)

{

if(currentNo == arr1[i1])

{

currentCount++

}

else

{

if(currentCount > maxCount)

{

maxCount = currentCount; maxNo = currentNo;

}

currentCount = 1;

currentNo = arr1[i1];

}

}

if(currentCount > maxCount)

{

maxCount = currentCount ; maxNo =currentNo ;

}

}

cout << "Longest repeating number is: " <

cout << " with count " << count[i1];

cout << endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!