Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
727 B
2
Indexable
#include <stdio.h>
#include <string.h>

int main() {
    char input_string[100];
    printf("Enter a string: ");
    fgets(input_string, 100, stdin);

    int length = strlen(input_string) - 1;
    int left = 0, right = length - 1;
    char encoded_string[100];

    for (int i = 0; i < length; i++) {
        if (left == right) {
            encoded_string[i] = input_string[left];
        } else if (i % 2 == 0) {
            encoded_string[i] = input_string[left];
            left++;
        } else {
            encoded_string[i] = input_string[right];
            right--;
        }
    }
    encoded_string[length] = '\0';

    printf("Encoded string: %s\n", encoded_string);
    return 0;
}