#include <stdio.h>
#include <stdlib.h>
void readArray(int arr[], int n) {
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
}
void displayArray(int arr[], int n) {
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}
int countInArray(int arr[], int n, int x) {
int count = 0;
for (int i = 0; i < n; i++) {
if (arr[i] == x) {
count++;
}
}
return count;
}
void removeZeros(int arr[], int *n) {
int j = 0;
for (int i = 0; i < *n; i++) {
if (arr[i] != 0) {
arr[j++] = arr[i];
}
}
*n = j;
}
int isPrime(int x) {
if (x <= 1) return 0;
for (int i = 2; i < x; i++) {
if (x % i == 0) {
return 0;
}
}
return 1;
}
void sortArray(int arr[], int n) {
int i = 0, j = n - 1;
while (i < j) {
while (isPrime(arr[i]) && i < j) {
i++;
}
while (!isPrime(arr[j]) && i < j) {
j--;
}
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
float avgDivisibleBy3(int arr[], int n) {
int sum = 0, count = 0;
for (int i = 0; i < n; i++) {
if (arr[i] % 3 == 0) {
sum += arr[i];
count++;
}
}
if (count == 0) return 0;
return (float) sum / count;
}
int main() {
int n;
scanf("%d", &n);
int arr[n];
readArray(arr, n);
printf("Original array: ");
displayArray(arr, n);
int x;
scanf("%d", &x);
int count = countInArray(arr, n, x);
printf("%d appears %d times in the array.\n", x, count);
removeZeros(arr, &n);
printf("Array after removing zeros: ");
displayArray(arr, n);
sortArray(arr, n);
printf("Array after sorting: ");
displayArray(arr, n);
float avg = avgDivisibleBy3(arr, n);
printf("Average of numbers divisible by 3: %.2