Answer to Question #207581 in C for Prasanna

Question #207581

Two of them travelling in a car who is sitting in back seat. He saw the mirror image of a word written on a vehicle as ecnalubma. Write a C programming to display the original word


input : ecnalubma


Output : ambulance


1
Expert's answer
2021-06-16T05:23:08-0400
#include <stdio.h>
#include <string.h>

char* reverse(char* str)
{
    size_t i, length;
    length = strlen(str);

    for(i = 0; i < length / 2; ++i)
    {
        char temp;
        temp = *(str + i);
        *(str + i) = *(str + length - i - 1);
        *(str + length - i - 1) = temp;
    }

    return str;
}


int main()
{
    char input[] = "ecnalubma";

    printf("Input:  %s\n", input);
    printf("Output: %s\n", reverse(input));

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS