To avoid duplicates while entering in an array, using a C Program

Leave a Comment
#include<stdio.h>
#include<conio.h>
int main()
{
int a[100],n,t,i,j;
printf("Enter the max limit:");
scanf("%d",&n);
printf("\nEnter the number:");
scanf("%d",&a[0]);
for(i=1;i{
printf("\nEnter the number:");
scanf("%d",&t);
for(j=0;j<n;i++){
if(t==a[j])
i--;
else
a[i]=t;
}
}

printf("\nThe array after avoiding the duplicate elements is\n\n");
for(i=0;i<n;i++){
printf("%d\t",a[i]);
}
getche();
return 0;
}

0 comments: