This commit is contained in:
2025-04-21 20:10:45 +08:00
parent 849819dff3
commit 9a7e511c12
7 changed files with 209 additions and 7 deletions
+26
View File
@@ -0,0 +1,26 @@
#include <stdio.h>
int search(int arr[], int value, int l, int r) {
int mid = (l + r) / 2;
if (l > r) {
return -1;
}
if (arr[mid] == value) {
return mid;
} else if (arr[mid] < value) {
return search(arr, value, mid + 1, r);
} else {
return search(arr, value, l, mid - 1);
}
}
int main() {
int arr[1005], n, i, value;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
scanf("%d", &value);
printf("%d\n", search(arr, value, 0, n - 1));
return 0;
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}
int main() {
int num;
scanf("%d", &num);
printf("%d\n", factorial(num));
return 0;
}
+26
View File
@@ -0,0 +1,26 @@
#include <stdio.h>
struct _Pair {
int x;
int y;
};
typedef struct _Pair Pair;
Pair fun(Pair p){
Pair q;
q.x = p.y;
q.y=p.x%p.y;
if (q.y!=0){
return fun(q);
}
return q;
}
void fake_fn(){}
int main() {
Pair p;
scanf("%d %d", &p.x, &p.y);
printf("%d\n", fun(p).x);
return 0;
}