import java.util.*;
class Frequency
{
public static void main(String ags[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i,j,count;
int a[]=new int[n];
for(i=0;i<n;i++)
a[i]=sc.nextInt();
int f[]=new int[n];
for(i=0;i<n;i++)
f[i]=-1;
for(i=0;i<n;i++)
{
count=1;
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
{
count++;
f[j]=0;
}
}
if(f[i]!=0)
f[i]=count;
}
for(i=0;i<n;i++)
{
if(f[i]!=0)
System.out.println("frequency of" +a[i]+"is "+f[i]);
}
}
}
i/p:10
1 2 3 1 2 4 6 3 1 2
o/p:
frequency of 1 is 3
frequency of 2 is 3
frequency of 3 is 2
frequency of 4 is 1
frequency of 6 is 1
class Frequency
{
public static void main(String ags[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i,j,count;
int a[]=new int[n];
for(i=0;i<n;i++)
a[i]=sc.nextInt();
int f[]=new int[n];
for(i=0;i<n;i++)
f[i]=-1;
for(i=0;i<n;i++)
{
count=1;
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
{
count++;
f[j]=0;
}
}
if(f[i]!=0)
f[i]=count;
}
for(i=0;i<n;i++)
{
if(f[i]!=0)
System.out.println("frequency of" +a[i]+"is "+f[i]);
}
}
}
i/p:10
1 2 3 1 2 4 6 3 1 2
o/p:
frequency of 1 is 3
frequency of 2 is 3
frequency of 3 is 2
frequency of 4 is 1
frequency of 6 is 1
No comments:
Post a Comment