I’m trying to print non-unique elements in an array. Consider the program below:
module nonunique;
int non_unique_array [1:10];
int i,j,count;
initial begin
non_unique_array = '{5,2,5,2,2,6,8,9,5,9};
$display("\n------------printing non-unique elements----------\n");
$display ("the values inside the array are");
for(i=1;i<=10;i++)
begin
$display("%d",non_unique_array[i]);
end
$display("the non unique values inside the array are\n");
for(i=1;i<=9;i++)
begin
for(j=i+1;j<=10;j++)
begin
count = 0;
if (non_unique_array[i] == non_unique_array[j])
begin
count++;
if (count == 1)
$display("%0d", non_unique_array[i]);
end
end
end
end
endmodule
The output I got:
# ------------printing non-unique elements----------
#
# the values inside the array are
# 5
# 2
# 5
# 2
# 2
# 6
# 8
# 9
# 5
# 9
# the non unique values inside the array are
#
# 5
# 5
# 2
# 2
# 5
# 2
# 9
The output I want is:
# ------------printing non-unique elements----------
#
# the values inside the array are
# 5
# 2
# 5
# 2
# 2
# 6
# 8
# 9
# 5
# 9
# the non unique values inside the array are
#
# 5
# 2
# 9
What should I do?
Thanks in advance!!