initial commit
This commit is contained in:
66
src/LAB4.c
Normal file
66
src/LAB4.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user