Advertisement
dxvmxnd

kpo_2_16_10

Oct 16th, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6. void changeStr(char* str, size_t size) {
  7. char temp;
  8. for (int i = 0; i < size / 2; i++) {
  9. temp = str[i];
  10. str[i] = str[i + size / 2];
  11. str[i + size / 2] = temp;
  12. }
  13. printf("Результат: %s\n", str);
  14. }
  15.  
  16.  
  17. int main() {
  18. char str[100];
  19.  
  20. printf("Введите строку:\n");
  21. fgets(str, sizeof(str), stdin);
  22.  
  23. size_t size = strlen(str);
  24. if (str[size - 1] == '\n') {
  25. str[size - 1] = '\0';
  26. size--;
  27. }
  28.  
  29. printf("Длина строки: %zu\n", size);
  30.  
  31. if (size % 4 == 0) {
  32. changeStr(str, size);
  33. } else {
  34. printf("Длина не кратна 4");
  35. }
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement