This commit is contained in:
justuser-31 2025-05-08 22:09:23 +03:00
parent 4f3ef139d0
commit ceed37d939
3 changed files with 55 additions and 0 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "STEP1_Basics/3_Formatting/c_cross_pack"]
path = STEP1_Basics/3_Formatting/c_cross_pack
url = ssh://git@git.del.pw:2222/justuser-31/c_cross_pack.git
[submodule "STEP1_Basics/5_Recursion/c_cross_pack"]
path = STEP1_Basics/5_Recursion/c_cross_pack
url = ssh://git@git.del.pw:2222/justuser-31/c_cross_pack.git

@ -0,0 +1 @@
Subproject commit 0d5a86a1586708ef6e77604b087e825a6f08490f

View File

@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <limits.h>
#include "c_cross_pack/libs/string.h"
int rmin(int* nums, int size, double i) {
if (i == INT_MIN) {
return rmin(nums, size - 1, nums[size]);
}
// If we at the end
if (size == 0) {
return nums[0];
}
else {
int next_i = rmin(nums, size - 1, nums[size]);
if (rmin(nums, size - 1, nums[size]) < nums[size]) {
return next_i;
}
else {
return nums[size];
}
}
}
int main() {
// Generate seed from now time in microseconds
struct timeval now;
gettimeofday(&now, NULL);
srandom(now.tv_usec);
string list = strInit("");
// Generate random nums under 100
int* nums = malloc(10 * sizeof(int));
for (int i = 0; i < 10; i++) {
nums[i] = random() % 100;
//printf("%d ", nums[i]);
strAdd(&list, int2Str(&nums[i]));
strAdd(&list, " ");
}
//printf("\n");
// Find min
int min = rmin(nums, 10, INT_MIN);
printf("Original list:\n%s\n"
"\nMin: %d\n", list, min);
return 0;
}