struct
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user