GIVEN AN ARRAY OF SIZE N , FIND ALL ELEMENTS THAT APPEAR MORE THAN N/K TIMES.
EX:
ENTER THE NO.OF DIGITS:
7
ENTER THE VALUE OF K:
3
ENTER THE ELEMENTS IN THE ARRAY:
1 1 1 3 2 2 2
THE ELEMENTS APPEAR MORE THAN N/3 TIMES :
1 2
PROGRAM
#include <stdio.h>
int main()
{
int a[100],n,i,k,j=0,count,b[20]={0,1,2,3,4,5,6,7,8,9};
printf("enter no.of digits");
scanf("%d",&n);
printf("enter the value of k");
scanf("%d",&k);
printf("enter the elements");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("the elements appear more than n/3 times\n");
for(j=0;j<10;j++)
{
count=0;
for(i=0;i<n;i++)
{
if(b[j]==a[i])
{
count++;
}
}
if(count>(n/k))
{
printf("%d ",b[j]);
}
}
return 0;
}
CLICK HERE TO SEE THE PREVIOUS PROGRAM
LEARN WITH JAGADEESH
Good problem sir
ReplyDeleteGood program
ReplyDeletePost a Comment