include <stdio.h>
#include <stdlib.h>
#include <string.h>
int truelength(int *arr,int *temp,int size){
int i=0,j,e=1,n=0;
temp[0]=arr[0];
while(i<size){
for(j=0;j<n;j++)
if(arr==temp[j])
{
e=0;
}
if(e==1)
{
temp[n]=arr;
n++;
}
i++;
e=1;
}
temp=realloc(temp,sizeof(int)*n);
return n;
}
int main(){
int i,e,n,j,size,*ptr,*temp,*newarry;
printf("Please enter the size ");
scanf("%d",&size);
ptr=(int *) malloc(sizeof(int)*size);
for(i=0;i<size;i++)
scanf("%d",&ptr);
temp=(int *) malloc(sizeof(int)*size);
n=truelength(ptr,temp,size);
printf("The size of the array %d\n",n);
printf("the values in the array are : ");
for(i=0;i<n;i++)
printf("%d ",temp);
free(temp);
free(ptr);
return 0;
} |