Upload files to "/"

This commit is contained in:
2025-10-04 15:12:10 +03:00
parent 1fb72dcee2
commit b49ec3a67c
5 changed files with 111 additions and 0 deletions

12
fib.c Normal file
View File

@@ -0,0 +1,12 @@
#include <stdio.h>
int fib(int n) {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
}
int main() {
int n = 10;
printf("%d fib element: %d\n", n, fib(n-1));
return 0;
}

23
main_prog.c Normal file
View File

@@ -0,0 +1,23 @@
#include <stdio.h>
int foo(int *a, int b){
printf("foo a %x \n");
*a = 1499;
return 42;
}
int
main(int argc, const char *argv[]) {
int arr[3] = {1, 2, 3};
printf("arr[1] = %d\n", arr[1]);
printf("hello world\n");
int *pa;
pa = arr;
printf("pa[0] = %d\n", pa[0]);
return 0;
int a = 13, b = 37;
foo(&a, b);
}

39
myatoi.c Normal file
View File

@@ -0,0 +1,39 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int myatoi(char *instr) {
int sign = 1;
if (*instr == '-') {
sign = -1;
instr++;
}
for (; *instr != '\0'; instr++) {
if (!isdigit(*instr)) {
return 0;
}
}
int num = 0;
instr -= strlen(instr);
while (*instr >= '0' && *instr <= '9') {
num = num * 10 + (*instr - '0');
instr++;
}
return num * sign;
}
int main() {
char input[] = "-2890";
int number = myatoi(input);
printf("Converted number is: %d\n", number);
char bad_input[] = "2890kjdfshdfsh";
number = myatoi(bad_input);
printf("Bad input result: %d\n", number);
return 0;
}

21
mystr_idx.c Normal file
View File

@@ -0,0 +1,21 @@
#include <stdio.h>
int mystr_idx(char *str, char *substr) {
for (int i = 0; str[i]; i++) {
int j = 0;
while (str[i + j] && substr[j] && str[i + j] == substr[j]) {
j++;
}
if (!substr[j]) {
return i;
}
}
return -1;
}
int main() {
char str[] = "Hello, world!";
char substr[] = "world";
int index = mystr_idx(str, substr);
printf("substring index '%s' in string '%s': %d\n", substr, str, index);
return 0;
}

16
mystrlen.c Normal file
View File

@@ -0,0 +1,16 @@
#include <stdio.h>
void mystrlen(const char *s) {
int length = 0;
while (s[length] != '\0') {
length++;
}
printf("Length: %d\n", length);
}
int main() {
const char *str = "hi!";
mystrlen(str);
return 0;
}