Advertisement
leo11

Untitled

Jun 13th, 2021
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.68 KB | None | 0 0
  1. //1)
  2. #include <stdio.h>
  3.  
  4. long long int recFact(int a)
  5. {
  6.     if( a < 0 ) return 0;
  7.     else if ( a == 0 ) return 1;
  8.     else return a * recFact( a - 1 );
  9. }
  10.  
  11. int main(){
  12.     int a;
  13.     scanf("%d", &a);
  14.     long long b = recFact(a);
  15.    
  16.     printf("%lld", b);
  17.  
  18.     return 0;
  19. }
  20.  
  21.  
  22. /////
  23. //2)
  24. #include <stdio.h>
  25.  
  26. double recPow(int a, int b)
  27. {
  28.     if (b == 0) return 1;
  29.     if (a == 0) return 0;
  30.     if (b > 0) return a * recPow(a, b-1);
  31.     if (b < 0) return (1.0/recPow(a, -b));
  32.     return 0;
  33. }
  34.  
  35. int main() {
  36.     int a, b;
  37.     scanf("%d%d", &a, &b);
  38.    
  39.     double k = recPow(a, b);
  40.     printf("%lf", k);
  41.    
  42.     return 0;
  43. }
  44.  
  45. //////////
  46. //3)
  47. #include <stdio.h>
  48.  
  49. void pr(int c)
  50. {
  51.     if (c == 0) return;
  52.  
  53.     int n;
  54.     scanf("%d", &n);
  55.     pr(c - 1);
  56.     printf("%d ", n);
  57.  
  58. }
  59.  
  60. int main() {
  61.     int a;
  62.     scanf("%d", &a);
  63.     pr(a);
  64.     return 0;
  65. }
  66.  
  67. ///////
  68. //4)
  69. #include <stdio.h>
  70. #include<stdlib.h>
  71. #include<string.h>
  72. void recDecToBin(int n, char* result)
  73. {
  74.     if (n < 0) return;
  75.  
  76.     int del = n%2;
  77.     n /= 2;
  78.     if (n == 0) {
  79.         if (del == 1)
  80.             strcat(result, "1");
  81.         else strcat(result, "0");
  82.     return;
  83.     }
  84.     recDecToBin(n, result);
  85.    
  86.     if (del == 1)
  87.         strcat(result, "1");
  88.     else strcat(result, "0");
  89. }
  90.  
  91. int main(){
  92.     int n;
  93.     // char result[30] = "";
  94.     char *result = (char*) malloc (30 * sizeof(char));
  95.     scanf("%d", &n);
  96.     // вызов функции recDecToBin
  97.     recDecToBin(n, result);
  98.     // puts(result);
  99.     printf("%s", result);
  100.     return 0;          
  101. }
  102.  
  103.  
  104. ////
  105. //5)
  106. #include <stdio.h>
  107.  
  108. static int count = 0;
  109. long long int recSum(long long int arr[])
  110. {
  111.     int i = count;
  112.     count++;
  113.    
  114.     if (count == 100) return arr[i];
  115.     return arr[i] + recSum(arr);
  116. }
  117.  
  118. int main() {
  119.     long long int arr[100];
  120.     for (int i = 0; i < 100; i++) scanf("%lld", &arr[i]);
  121.    
  122.     long long int k = recSum(arr);
  123.    
  124.     printf("%lld", k);    
  125.    
  126.     return 0;
  127. }
  128.  
  129.  
  130. ///////
  131. //6)
  132. #include <stdio.h>
  133. #include <stdlib.h>
  134. int n, m, k = 0;
  135. int labirint(int **a, int x, int y){
  136.     if (a[x][y] == 1) return 0;
  137.     a[x][y] = 1;
  138.     if (x == n-1 && y == m-1) k = 1;
  139.     if (x-1>=0) labirint(a, x-1, y);
  140.     if (y-1>=0) labirint(a, x, y-1);
  141.     if (y+1<m) labirint(a, x, y+1);
  142.     if (x+1<n) labirint(a, x+1, y);
  143.     if (k == 1) return 1;
  144.     else return 0;
  145. }
  146.  
  147. int main() {
  148.     scanf("%d%d", &n, &m);
  149.     int **a = malloc(n * sizeof(int*));
  150.     for (int i = 0; i < n; i++){
  151.         a[i] = malloc(m * sizeof(int));
  152.         for(int j = 0; j < m; j++){
  153.             scanf("%d", &a[i][j]);
  154.         }
  155.     }
  156.     if(labirint(a, 0, 0)) printf("exists");
  157.     else printf("doesn't exist");
  158.     return 0;
  159. }
  160.  
  161.  
  162. ///////
  163. 7)
  164. #include <stdio.h>
  165. #include <stdlib.h>
  166. int h, w;
  167.  
  168. int count(int* * a, int x, int y, int tmp){
  169.     if(a[y][x] == 0)return tmp;
  170.     a[y][x] = 0;
  171.     tmp++;
  172.  
  173.     if (x-1>=0) tmp = count(a, x-1, y, tmp);
  174.     if (y-1>=0) tmp = count(a, x, y-1, tmp);
  175.     if (y+1<h) tmp = count(a, x, y+1, tmp);
  176.     if (x+1<w) tmp = count(a, x+1, y, tmp);
  177.     return tmp;
  178. }
  179.  
  180.  
  181. int main(){
  182.     int max = 0;
  183.     scanf("%d%d", &h, &w);
  184.     int* * arr = malloc(h* sizeof(int *));
  185.     for(int i = 0; i < h; i++){
  186.         arr[i] = malloc(w * sizeof(int));
  187.         for(int j = 0; j < w; j++){
  188.             scanf("%d", &arr[i][j]);
  189.         }
  190.     }
  191.  
  192.     for(int i = 0; i < h; i++) {
  193.         for (int j = 0; j < w; j++) {
  194.  
  195.             if (arr[i][j] == 1) {
  196.                 int tmp = 0;
  197.                 tmp = count(arr, j, i, tmp);
  198.                 if (tmp>max)max = tmp;
  199.             }
  200.         }
  201.  
  202.     }
  203.     printf("%d", max);
  204.     return 0;
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement