Advertisement
yanni_yagami

Untitled

Jul 19th, 2020
1,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void)
  5. {
  6.   int i, j, k, half;
  7.   char str[256], str2[256], finlaStr[256];
  8.   scanf("%s", str);
  9.  
  10.   half = strlen(str)/2;
  11.  
  12.   if(strlen(str) % 2) half++;
  13.  
  14.   /* Split the string */
  15.   for(i = 0, j = half; j < strlen(str);i++ ,j++)
  16.   {
  17.     str2[i] = str[j];
  18.   }
  19.   str2[i] = '\0';
  20.   str[half] = '\0';
  21.  
  22.   /* constructing the final string based on the two halves */
  23.   for(i = 0, k = 0; i < half; i++, k += 2)
  24.   {
  25.     finlaStr[k] = str[i];
  26.     finlaStr[k+1] = str2[i];
  27.   }
  28.   finlaStr[k] = '\0';
  29.  
  30.   printf("%s\n", finlaStr);
  31.  
  32.   return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement