Files
LAB16/src/LAB4.c
2026-02-25 18:09:22 +03:00

67 lines
1.2 KiB
C

#include <stdint.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include "../include/LAB4.h"
#define MAX_SIZE 15
void lab_4()
{
size_t size;
do
{
printf("Enter array size (1..=15): ");
READ_EXACT("%zu", size);
if (size == 0)
{
printf("Size cannot be zero, try again\n");
continue;
}
else if (size > MAX_SIZE)
{
printf("Size cannot be greater than %d, try again\n", MAX_SIZE);
continue;
}
break;
}
while (1);
int32_t* array = malloc(size * sizeof(int32_t));
if (array == NULL)
{
printf("Allocation failure");
return;
}
for (size_t i = 0; i < size; ++i)
{
printf("Enter array[%zu]: ", i);
READ_EXACT("%d", array[i]);
}
uint8_t r = 0;
printf("Array = [ ");
for (size_t i = 0; i < size; ++i)
{
if (array[i] < 0 && abs(array[i]) > 10)
{
r += 1;
}
if (i > 0)
{
printf(", ");
}
printf("%d", array[i]);
}
printf(" ]\nCount of |x| > 10: %d\n", r);
free(array);
}