Reverse in Place

Lab C Beginner 10 points

Read a word and reverse it in place by swapping characters from both ends, then print it.

Input

One word.

Output

The reversed word.

Example

Input

hello

Output

olleh
Sample input available Sample output available
Editor
C

Hints

Two indexes walk towards the middle, swapping as they go.

Solution explanation

The two-index technique reverses without a second buffer.

Show solution
#include <stdio.h>
#include <string.h>

int main() {
    char s[100];
    scanf("%s", s);
    int i = 0, j = strlen(s) - 1;
    while (i < j) {
        char t = s[i];
        s[i] = s[j];
        s[j] = t;
        i++;
        j--;
    }
    printf("%s\n", s);
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD