20120113

Program in C to reverse a string

Program in C to reverse a string,Reversing a String

#include<stdio.h>
void reverse(char s[]);
int main()
{
char text[50]="India";
printf("\n Text is :%s",text);
reverse(text);
printf("\n Reversed Text is :%s \n",text);
return 0;
}
void reverse(char s[])
{
int c,i,j;
for(i=1,j=strlen(s)-1; i<j; i++,j--)
        {
        c=s[i];
        s[i]=s[j];
        s[j]=c;
        }
}
Previous                             Home                               Next

No comments:

Post a Comment