Remove duplicate elements from an array, stored into another array and sort in ascending order
PROGRAM:
PROGRAM:
#include <stdio.h> | |||
int main() | |||
{ | |||
int n, a[100],b[100],i,j,k=0; | |||
scanf("%d",&n); | |||
for(i=0;i<n;i++) | |||
{ | |||
scanf("%d",&a[i]); | |||
} | |||
for(i=0;i<n;i++) | |||
{ | |||
int c=0; | |||
for(j=i+1;j<n;j++) | |||
{ | |||
if(a[i]==a[j]) | |||
{ | |||
c=1; | |||
break; | |||
} | |||
} | |||
if(c==0) | |||
{ | |||
b[k]=a[i]; | |||
k++; | |||
} | |||
} | |||
for(i=0;i<k;i++) | |||
{ | |||
int t; | |||
for(j=i+1;j<k;j++) | |||
{ | |||
if(b[i]>b[j]) | |||
{ | |||
t=b[i]; | |||
b[i]=b[j]; | |||
b[j]=t; | |||
} | |||
} | |||
} | |||
for(i=0;i<k;i++) | |||
{ | |||
printf(" %d",b[i]); | |||
} | |||
} | |||
OUTPUT:
5
12 34 34 56 78
Sorted Array is
12 34 56 78
|
No comments:
Post a Comment