C Code 24 _ To print the elements repeating more thrice(including three times) in the given array along with there frequencies [Zoho Coding Round Question]
Program:
#include<stdio.h>
int main()
{
int
a[50],b[50],c[50],d[50];
int
n,i,j,t,k=1,l=1,m=0,f=0;
printf("Enter
# of elements : ");
scanf("%d",&n);
printf("\n\nEnter
%d elements : ",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
for(i=0;i<n-1;i++)
{
for(j=i;j<n;j++)
{
if(b[i]<b[j])
{
t=b[j];
b[j]=b[i];
b[i]=t;
}
}
}
printf("sorted
array : ");
for(i=0;i<n;i++)
{
printf("%d
",b[i]);
}
c[0]=b[0];
for(i=1;i<n;i++)
{
if(b[i]==b[i-1])
{
l=l+1;
}
if(b[i]!=b[i-1])
{
c[k]=b[i];
k=k+1;
d[m]=l;
m=m+1;
l=1;
}
}
for(i=0;i<m;i++)
{
if(d[i]>=3)
{
printf("\n\n%d
: %d times",c[i],d[i]);
f=1;
}
}
if(f==0)
{
printf("\n\nNo
element in array is repeated more than three times");
}
return
0;
}
Output:
Thank You ...
0 comments: