Menu Close

Write the code to change the display in reverse order using pointer

Yasir was traveling from Chennai to Bangalore by bus. He looking the LED display board for the destination place name on the bus. But it shows the reflection of the destination place name in reverse. can you write the code to change the display in reverse order?

Input:
The input line must be a string.

Output:
Print reverse a string.
#include <stdio.h>
int main()
{ char *sptr;char *rptr;
  char s[20];int i=0;
  scanf("%[^\n]s",s);
  sptr = s;rptr = sptr;
//you can use strlen to find length of the string
  while(*sptr!='\0'){  
  sptr++;
  i+=1;}
  while(i>=0){
  printf("%c",*(rptr+i));
  i--;}
return 0;
}

INPUT_1:
erolagnaB

OUTPUT:
Bangalore


INPUT_2:
iabmuM  salem

OUTPUT:
melas  Mumbai


INPUT_3:
fcuk  the  code

OUTPUT:
edoc  eht  kucf


INPUT_4:
edoc  eht  kucS

OUTPUT:
Scuk  the  code


INPUT_5:
edoc  eht  kucf  olleh

OUTPUT:
hello  fcuk  the  code


ILLUSTRATION

Executed using gcc

Morae Q!