I have written a C program to delete an element an element in an array.The element get deleted as per the output of the program. The problem is that the next element near to the deleted element get print twice. I have tried to correct the code. I have found many codes available in Internet which is different from what I have created on my own. It will be more helpful to learn coding if I could correct my code. So, kindly please help me to rewrite my code by rectifying the errors. I am attaching the code below.
#include <stdio.h>
int main( )
{
int arr[1000];
int n;
int i;
int del;
int temp;
printf("Enter the size of array\n");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
}
printf("Elements are\n");
for(int i=0;i<n;i++){
printf("%d\n",arr[i]);
}
printf("enter the element to be deleted:\n");
scanf("%d",&del);
for(i=0;i<n;i++){
if(arr[i]==del){
temp=arr[i];
arr[i]=arr[i+1];
}
}
printf("After deletion:");
for(int i=0;i<n;i++){
printf("%d\n",arr[i]);
}
return 0;
}
Kindly help me.Thanks in advance!