Tuesday, 17 March 2015

Program to reverse the given string Using C


# include <stdio.h>
# include <conio.h>

void main()
{
char str[20], rev[20] ;
int i, j, l ;
clrscr() ;
printf("Enter a string : ") ;
scanf("%s", str) ;
for(l = 0 ; str[l] != '\0' ; l++) ;
for(i = l - 1, j = 0 ; i >= 0 ; i--, j++)
rev[j] = str[i] ;
rev[j] = '\0' ;
printf("\nThe given string is : %s\n\n", str) ;
printf("The reversed string is : %s", rev) ;
getch() ;
}

RUN 1 :
~~~~~~~
Enter a string : bhuvan
The given string is : bhuvan
The reversed string is : navuhb

No comments:

Post a Comment