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
#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;
}
Comments
Leave a comment