C Program To Reverse the String without using "strrev()" function

Ex: Write a C Program To Reverse the String without using "strrev()" function. How to write a C Program To Reverse the String without using "strrev()" function. C Program To Reverse the String without using "strrev()" function.




Program:

#include<stdio.h>
#include<string.h>
void main()
{
char a[100],b[100];
int i,j,len;

printf(" \n Please Enter Any String : ");
gets(a);

j=0;
/*Calculate length of string using strlen() function and store result in variable len*/
len=strlen(a);

//Run for loop from len-1 to 0.
for(i=len-1;i>=0;i--)
{
//store reversed string in array b.
b[j]=a[i];
    j++;
}
//Print reversed string
printf("\n String After Reversing = %s",b);

}



Above Program show's the following output:

C Program To Reverse the String without using "strrev()" function


No comments:

Post a Comment

If you have any doubts, please discuss here...👇