Here I’m sharing a code to print any inputted sting as reverse method. For Example if we input APPS then output should be SSPA.
Strrev() function in C do the same thing. By using this function easily can print a String in reverse but here we perform Reverse opertion without using Strrev().
Let See our Code :
<pre class="brush: cpp"
>
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char *str;
int i,len;
clrscr();
printf("Enter Any String for Reverse Print : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
str[i]+=str[len];
str[len]=str[i]-str[len];
str[i]=str[i]-str[len--];
}
printf("nnReverse String is : %s",str);
getch();
}
</pre>
</pre>
No comments:
Post a Comment