Zoho second round Print the elements of an array in the decreasing frequency.
Print the elements of an array in the decreasing frequency.
Examples:
Happy coding
Examples:
Input: arr[] = {2, 5, 2, 8, 5, 6, 8, 8} Output: arr[] = {8, 8, 8, 2, 2, 5, 5, 6} Input: arr[] = {2, 5, 2, 6, -1, 9999999, 5, 8, 8, 8} Output: arr[] = {8, 8, 8, 2, 2, 5, 5, 6, -1, 9999999}
C programming
#include<stdio.h>
#include<conio.h>
int main()
{
int i=0,n,num[100],j=0,temp=0,count=0,k=0,max=0,l=0,m=0;
int a[100],b[100];
scanf("%d",&n);
for (i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(num[i]<num[j])
{
temp =num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
for(i=0;i<n;i=j)
{
for(j=i+1;num[i]==num[j];j++)
{
count+=1;
}
a[k]=num[i];
b[k]=count+1;
k+=1;
count=0;
}
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
if(max<b[j])
{max=b[j];l=j;}
}
for(m=0;m<max;m++){printf("%d ",a[l]);}
b[l]=0;
max=0;
}
getch();
return 0;
}
Happy coding
Comments
Post a Comment