C PROGRAM FOR STRING REVERSE
There are a number of ways one can reverse strings. Here are a few of them.
These should be enough to impress the interviewer! The methods span from
recursive to non-recursive (iterative). Also note that there is a similar question
about reversing the words in a sentence, but still keeping the words in place. That is
I am a good boy
would become
boy good a am I
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
char n[50],j,i=0;
clrscr();
printf("OUTPUT\n");
printf("------");
printf("Enter String:\n");
printf("The Reverse Of The Given String is\n");
printf("**********************************");
while((n[i]=getchar())!='\n')i++;
for(j=i-1;j>=0;j--)
{
printf("%c",n[j]);
}
getch();
}

0 comments:
Post a Comment