#include<stdio.h>
#include<conio.h>
int main()
{
int *a;
int i,j,n,c=1,temp,index;
clrscr();
printf("Enter Array size:");
scanf("%d",&n);
a=(int*) malloc (n * sizeof(int));
if(a==NULL)
{
printf("**Memory is not allocated**");
exit(0);
}
else
{
printf("**Memory is successfully allocated**");
printf("\nEnter %d elements in Array:\n",n);
for(i=0; i<n; i++)
{
scanf("%d",a+i);
}
//Sorting elements of Array.
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
if(*(a+i)>*(a+j))
{
*(a+i)=*(a+i)+*(a+j);
*(a+j)=*(a+i)-*(a+j);
*(a+i)=*(a+i)-*(a+j);
}
}
}
//Comparing elements of Array.
for(i=0;i<n;)
{
for(j=i+1; j<n; j++)
{
if(*(a+i)==*(a+j))
{
c=c+1;
}
}
index=i;
i=i+c;
printf("\n%d is occurred in Array %d times.",a[index],c);
c=1;
}
}
return 0;
}
*** Input && Output ***
0 Comments