My source code:
#include<stdio.h>
#include<stdlib.h>
int main() {
int val, n = 2, i = 0;
int *arr = (int *) calloc(5, sizeof(int));
while (1 == 1) {
printf("Enter the value for array: ");
scanf("%d", &val);
arr[i] = val;
printf("arr[%d]=%d\n", i, arr[i]);
i++;
if (i % 5 == 0) {
int ans1;
printf("Do you want expand array?\n");
scanf("%d", &ans1);
if (ans1 == 1) {
arr = (int *) realloc(arr, n * 5 * sizeof(int));
n++;
} //end inner if
} //end inner if
for (int j = 0; j < i; j++)
printf("arr[%d]=%d\n", j, arr[j]);
} //end while
} //end main
How can I add shrink function like for instance: if count of zeros entered by user is more than 5, shrink function will delete them and shift elements?