top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

+1 vote
409 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 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
#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;
}
answer Jul 5, 2017 by Leon Martinović
Similar Questions
0 votes

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

0 votes

Given an unordered array A of size n and integer x. What is the best complexity to find two elements in A whose sum is x?
Share the algo, its complexity and if possible C code.

...