Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1)
- #include <stdio.h>
- long long int recFact(int a)
- {
- if( a < 0 ) return 0;
- else if ( a == 0 ) return 1;
- else return a * recFact( a - 1 );
- }
- int main(){
- int a;
- scanf("%d", &a);
- long long b = recFact(a);
- printf("%lld", b);
- return 0;
- }
- /////
- //2)
- #include <stdio.h>
- double recPow(int a, int b)
- {
- if (b == 0) return 1;
- if (a == 0) return 0;
- if (b > 0) return a * recPow(a, b-1);
- if (b < 0) return (1.0/recPow(a, -b));
- return 0;
- }
- int main() {
- int a, b;
- scanf("%d%d", &a, &b);
- double k = recPow(a, b);
- printf("%lf", k);
- return 0;
- }
- //////////
- //3)
- #include <stdio.h>
- void pr(int c)
- {
- if (c == 0) return;
- int n;
- scanf("%d", &n);
- pr(c - 1);
- printf("%d ", n);
- }
- int main() {
- int a;
- scanf("%d", &a);
- pr(a);
- return 0;
- }
- ///////
- //4)
- #include <stdio.h>
- #include<stdlib.h>
- #include<string.h>
- void recDecToBin(int n, char* result)
- {
- if (n < 0) return;
- int del = n%2;
- n /= 2;
- if (n == 0) {
- if (del == 1)
- strcat(result, "1");
- else strcat(result, "0");
- return;
- }
- recDecToBin(n, result);
- if (del == 1)
- strcat(result, "1");
- else strcat(result, "0");
- }
- int main(){
- int n;
- // char result[30] = "";
- char *result = (char*) malloc (30 * sizeof(char));
- scanf("%d", &n);
- // вызов функции recDecToBin
- recDecToBin(n, result);
- // puts(result);
- printf("%s", result);
- return 0;
- }
- ////
- //5)
- #include <stdio.h>
- static int count = 0;
- long long int recSum(long long int arr[])
- {
- int i = count;
- count++;
- if (count == 100) return arr[i];
- return arr[i] + recSum(arr);
- }
- int main() {
- long long int arr[100];
- for (int i = 0; i < 100; i++) scanf("%lld", &arr[i]);
- long long int k = recSum(arr);
- printf("%lld", k);
- return 0;
- }
- ///////
- //6)
- #include <stdio.h>
- #include <stdlib.h>
- int n, m, k = 0;
- int labirint(int **a, int x, int y){
- if (a[x][y] == 1) return 0;
- a[x][y] = 1;
- if (x == n-1 && y == m-1) k = 1;
- if (x-1>=0) labirint(a, x-1, y);
- if (y-1>=0) labirint(a, x, y-1);
- if (y+1<m) labirint(a, x, y+1);
- if (x+1<n) labirint(a, x+1, y);
- if (k == 1) return 1;
- else return 0;
- }
- int main() {
- scanf("%d%d", &n, &m);
- int **a = malloc(n * sizeof(int*));
- for (int i = 0; i < n; i++){
- a[i] = malloc(m * sizeof(int));
- for(int j = 0; j < m; j++){
- scanf("%d", &a[i][j]);
- }
- }
- if(labirint(a, 0, 0)) printf("exists");
- else printf("doesn't exist");
- return 0;
- }
- ///////
- 7)
- #include <stdio.h>
- #include <stdlib.h>
- int h, w;
- int count(int* * a, int x, int y, int tmp){
- if(a[y][x] == 0)return tmp;
- a[y][x] = 0;
- tmp++;
- if (x-1>=0) tmp = count(a, x-1, y, tmp);
- if (y-1>=0) tmp = count(a, x, y-1, tmp);
- if (y+1<h) tmp = count(a, x, y+1, tmp);
- if (x+1<w) tmp = count(a, x+1, y, tmp);
- return tmp;
- }
- int main(){
- int max = 0;
- scanf("%d%d", &h, &w);
- int* * arr = malloc(h* sizeof(int *));
- for(int i = 0; i < h; i++){
- arr[i] = malloc(w * sizeof(int));
- for(int j = 0; j < w; j++){
- scanf("%d", &arr[i][j]);
- }
- }
- for(int i = 0; i < h; i++) {
- for (int j = 0; j < w; j++) {
- if (arr[i][j] == 1) {
- int tmp = 0;
- tmp = count(arr, j, i, tmp);
- if (tmp>max)max = tmp;
- }
- }
- }
- printf("%d", max);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement