BCA

C LAB :PART A

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10

C LAB : PART B

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10

9. Write a C Program to remove Duplicate Element in a single dimensional Array.

 


/*Write a C Program to remove Duplicate Element in a single dimensional Array */


#include< stdio.h>

#include< conio.h>


// Code without the usage of pointers
int remove_duplicate_elements(int arr[], int n)
{
int j=0,i,te=0,flag=1;
int temp[10];

if (n==0 || n==1)
return n;


temp[0]=arr[0];


for (i=1; i< n; i++)
{
flag=1;
    for(j=0;j< i ; j++)
    
    {
    
        if(temp[j]==arr[i])
        flag=0;

    }
    if(flag==1)
    {
        temp[te]=arr[i];
        te++;
    }

}
 

    for (i=0; i< j; i++)
    arr[i] = temp[i];

return te;
}


void main()
{
int n;

int arr[200];
int i;
printf("Enter array size:");
scanf("%d",&n);
for(i = 0; i < n; i++)
{
scanf("%d",&arr[i]);
}

n = remove_duplicate_elements(arr, n);

printf("  Array Elements :");
for (i=0; i< n; i++)
printf(" %d ",arr[i]);

getch();
}