# C: Find out the length of the sequence of repeated elements in a array of integers?

+1 vote
89 views

Given a array of integers there is one that is repeated several time. How would you compute the length of the sequence of repeated elements.

posted May 30, 2017

``````#include<stdio.h>
#include<string.h>

int check_element(int str[],int curent_number,int index,int size)
{
int counter = 0;
int sequence=1;

while(counter != size)
{
if(index == counter)
counter++;

if(counter != size)
{
if (curent_number == str[counter])
sequence++;
}

counter++;
}

return sequence;
}

int main(void)
{
int str[] = {2,1,3,4,5,6,1,66,66,96,7,77,28,22,1,29,1,90,98,1,92,1};
int temp = 0,size;
int i= 0;
int sequence = 1;

size = (sizeof(str) / sizeof(str[0]));

while(i != size )
{
sequence = check_element(str,str[i],i,size);

if(sequence !=  1)
{
printf(" number %d with repeating of %d times ",str[i],sequence);
break;
}
else
{
i++;
}
}

getchar();
getchar();

return 0;
}
``````
Similar Questions

Given an array of sorted integers and find the closest value to the given number. Array may contain duplicate values and negative numbers.

Example : Array : 2,5,6,7,8,8,9
Target number : 5
Output : 5

Target number : 11
Output : 9

Target Number : 4
Output : 5