Advertisement
STANAANDREY

tpa rec 1

Mar 31st, 2023
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void fibs(int n, char s1[], char s2[], int i) {
  6.   if (n == 1) {
  7.     puts(s1);
  8.     return;
  9.   }
  10.   if (n == 2) {
  11.     puts(s2);
  12.     return;
  13.   }
  14.   int len1 = strlen(s1);
  15.   int len2 = strlen(s2);
  16.   char *s3 = malloc(sizeof(char) * (len1 + len2 + 1));
  17.   s3[0] = 0;
  18.   strcat(s3, s1);
  19.   strcat(s3, s2);
  20.   if (n == i) {
  21.     puts(s3);
  22.     free(s3);
  23.     return;
  24.   }
  25.   fibs(n, s2, s3, i + 1);
  26.   free(s3);
  27. }
  28.  
  29. int main(void) {
  30.   int n = 4;
  31.   char s1[] = "ads", s2[] = "123";
  32.   fibs(n, s1, s2, 3);
  33.   return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement