C Code 14 _ To find unique elements in an array and find the third largest number in the array
Program:
#include<stdio.h>
int main()
{
int
n,i,j,t,a[30],b[30];
printf("Enter
the no of elements : ");
scanf("%d",&n);
printf("\nEnter %d elements : ",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i;j<n;j++)
{
if(a[j]>a[i])
{
t=a[j];
a[j]=a[i];
a[i]=t;
}
}
}
printf("\nThe
array in sorted order (descending) : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
printf("\nThe
array in sorted order (ascending) : ");
for(i=n-1;i>=0;i--)
{
printf("%d ",a[i]);
}
b[0]=a[0];
j=1;
for(i=1;i<n;i++)
{
if(a[i]!=a[i+1])
{
b[j]=a[i];
j++;
}
}
printf("\nUnique elements in array : ");
for(i=0;i<j;i++)
{
printf("%d ",b[i]);
}
printf("\nThe
Third largest element is %d",b[2]);
getch();
return 0;
}
Output:
Thank You ...
0 comments: