forked from bghanchi/Coding-Interview-Question
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17EGICS068_Array_1.c
More file actions
49 lines (48 loc) · 793 Bytes
/
17EGICS068_Array_1.c
File metadata and controls
49 lines (48 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
int main()
{
int *a,*c,*g,n,i,j,temp,l,pos;
printf("enter the length of the array required ");
scanf("%d",&n);
c=n;
a = (int*)malloc(n * sizeof(int));
c = (int*)malloc(n * sizeof(int));
g = (int*)malloc(n * sizeof(int));
for(i=0;i<n;i++)
{
c[i]=0;
}
for(i=0;i<n;i++)
{
printf("enter the %dth element\n",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i]==a[j])
c[i]=c[i]+1;
}
}
for(i=0;i<n;i++)
{
g[i]=c[i];
}
for(i=1;i<n;i++)
{
temp=c[i];
l=i-1;
while((temp<c[j])&&(l>=0)){
c[l+1]=c[l];
l=l-1;
}
c[l+1]=temp;
}
for(i=0;i<n;i++)
{
if(c[0]==g[i])
pos = i;
}
printf("the max frequency element is %d with frequency as %d",a[pos],c[0]);
}