The task is to take array size (n) and array elements from stdin. Then check if the element is divisible by its last digit and then output only those elements. I can't use an extra array for this.
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int main()
{
int n;
int a[MAX];
printf("Enter array length:\n");
scanf("%d", &n);
if(n <= 0 || n > MAX)
{
printf("Err");
exit(EXIT_FAILURE);
}
for(int i = 0; i < n; i++)
{
scanf(" %d", &a[i]);
int last_digit = a[i] % 10;
if(a[i] % last_digit == 0)
{
printf("%d ", a[i]);
}
}
printf("\n");
exit(EXIT_SUCCESS);
}
So I'm stuck at the point where I somehow need to mark positions of these digits and keep them or alternatively remove those that don't fit the criteria. Also, there are negative numbers in the array.