Google Ads

Wednesday, May 27, 2009

Reversing a String

REVERSING A GIVEN STRING

#include”stdio.h”

#include “conio.h”

#include

void main()

{

char str1[10],str2[20];

int len,i,j;

clrscr();

printf("\nEnter the String : ");

gets(str1);

len=strlen(str1);

for(i=len-1,j=0;i>=0;i--,j++)

str2[j]=str1[i];

str2[j]=’\0’;

printf("\nThe Reversed String : %s",str2);

getch();

}

Output will be

Enter the String : good

The Reversed String : doog


No comments:

Post a Comment