top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Given an array, How to find the first element that appears an even number of times?

+1 vote
689 views
Given an array, How to find the first element that appears an even number of times?
posted Dec 15, 2015 by anonymous

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

2 Answers

0 votes
#include<stdio.h>
void even(int arr[],int n)
{
    int i,count=0,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(arr[i]==arr[j])
            {
                count++;    
            }
        }

        if(count%2==0)
        {
            printf("%d",arr[i]);
            break;
        }
        count=0;        
    }
}

int main()
{
    int arr[50];
    int n,i;
    printf("ENTER THE SIZE OF ARRAY: ");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("arr[%d]=",i);
        scanf("%d",&arr[i]);

    }
    even(arr,n);
}
answer Dec 16, 2015 by Shishir Chaudhary
0 votes

Algorithm :
1: scan the array from left to right.
1.a: Make count array to each element of given array.
2. scan count array from left to right.
2.a check current count array element is divisible by 2
2.b Print that element and stop
3: exit.

answer Dec 20, 2015 by Rajan Paswan
Similar Questions
0 votes

Given an unsorted array which has a number in the majority (a number appears more than 50% in the array), how to find that number?

+2 votes

Given an infinite supply of coins of denominations {20,10,5,1}, find out total number of way to make change of given amount - 'n'?
For example, if given amount is 20, there are 10 ways to make this change as shown below -
(1 of 20),(1 of 10 + 2 of 5),(1 of 10 + 1 of 5 + 5 of 1),(1 of 10 + 10 of 1), (2 of 10), (1 of 5 + 15 of 1),(2 of 5 + 10 of 1),(3 of 5 + 5 of 1),(4 of 5),(20 of 1)

If the amount given is 0 then the total number of ways to make change is 1 - using 0 coins of every given denomination.

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 array of integers, rearrange the array in such a way that the first element is first maximum and second element is first minimum.

...