Problem Statement:
Write a c program to reverse a string without using string reverse function.
Note: Here we use a temp variable in for loop to reverse a string. So this method is also known as reverse a string using temp.
Solution
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j;
char s[1000],t;
scanf("%s",s);
n=strlen(s);
for(i=0,j=n-1;i<n/2;i++,j--)
{
t=s[i];
s[i]=s[j];
s[j]=t;
}
printf("%s",s);
}
Input
Rajesh
Ouput
hsejar
Input
Thulasi
Output
isaluht