In reply to KillSteal:
Hey!! Thanks for the solution. Also, I’ve tried a code and it works fine!! Here it goes:
module zero;
int i,j,temp;
int a[10];
initial
begin
a = {0,1,0,2,1,0,0,0,9,8};
$display("\nThe elements in the array INITIALLY are:\n");
foreach(a[i])
begin
if (i % 2 != 0)
$display("a[i=%0d] = %0d --- INDEX = %0d",i,a[i],i);
else
$display("a[i=%0d] = %0d",i,a[i]);
end
$display("\n\nThe elements in the array AFTER re-arranging is:\n");
for (i = 0; i <= 9; i++)
begin
if (a[i] == 0 && i % 2 == 0)
begin
for (j = 0; j <= 9; j++)
begin
if (a[j] != 0 && j % 2 != 0)
begin
temp = a[j];
a[j] = a[i];
a[i] = temp;
break;
end
end
end
end
foreach(a[i])
begin
if (i % 2 != 0)
$display("a[i=%0d] = %0d --- INDEX = %0d",i,a[i],i);
else
$display("a[i=%0d] = %0d",i,a[i]);
end
end
endmodule