Last active
October 3, 2022 20:05
-
-
Save Airbus5717/00f36ee6eb8774c001991a1d5c9bf581 to your computer and use it in GitHub Desktop.
some random code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MACROS AND TYPEDEFS | |
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <stdbool.h> | |
typedef unsigned int uint; | |
#define UNUSED(x) ((void)(x)) | |
bool is_prime(uint n) | |
{ | |
if (n < 2) | |
return 0; | |
if (n < 4) | |
return 1; | |
if (n % 2 == 0 || n % 3 == 0) | |
return 0; | |
for (uint i = 5; i * i <= n; i = i + 6) | |
if (n % i == 0 || n % (i + 2) == 0) | |
return 0; | |
return 1; | |
} | |
void do_the_thing(uint y) { | |
const int size = 20; | |
uint* list = (uint *)malloc(sizeof(uint) * size); | |
assert(list); // assert if not null | |
srand(time(NULL)); | |
for (int i = 0; i < size; ++i) | |
list[i] = rand() % (y + 100) + 3; | |
puts("["); | |
for (int i = 0; i < size; ++i) { | |
uint s = list[i]; | |
printf("%u ", s); | |
if (is_prime(s)) printf("prime, "); | |
if (s % 2 == 0) puts("even"); | |
else puts("odd"); | |
} | |
puts("]"); | |
free(list); | |
} | |
int main(void) { | |
do_the_thing(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment