MIPI_BaseC_WebinarFRTK/21_Seminar08/02_random_generator_p5.c

32 lines
516 B
C
Raw Permalink Normal View History

2024-11-13 09:22:28 +03:00
#include <stdio.h>
#include <stdlib.h>
enum {SIZE = 10, SEED = 123};
int random_number(int n)
{
return rand() % n;
}
void init_array(int size, int a[], int max_random)
{
for (size_t i = 0;i<size;i++)
a[i]=random_number(max_random) - max_random/2;
}
void print_array(int size, int a[])
{
for (size_t i = 0; i < size; i++)
printf("%d ",a[i]);
printf("\n");
}
int main(void)
{
int a[SIZE];
srand(SEED);
init_array(SIZE, a, 100);
print_array(SIZE,a);
return 0;
}