How can I delete every nth element of an array?
For exp: i have and array a[]={2,12,4,5,67,33,24,45,6,1};
and i want to delete every 3rd element so that resultant array is a[]={2,12,5,67,24,45,1};
I know how to delete one element at one place but i can't find a way to delete the element on every 3rd place.
So i tried something like this:
int n,i;
double *a;
printf("Enter number of elements: ");
scanf_s("%d",&n);
a = (double*)malloc(100*sizeof(n));
printf("Enter the elements: ");
for( i=0;i<n;i++) {
scanf_s("%d",&a[i]);
}
for( i=0;i<n;i++) {
printf("%d ",a[i]);
}
for(i=0;i<n;i++){
for ( i = 3 - 1 ; i < n - 1 ; i++ ){
a[i] = a[i+1];
}
}
printf("\nResultant array is\n");
for( i = 0 ; i < n - 1 ; i++ )
printf("%d\n", a[i]);
and there isn't any particular way that i need to do this, it can be in the same array or in a new array.