Reverse the given String

Description

Get a String and reverse the characters of the string
Input:
Hello
Output:
olleH

Solution

#include<stdio.h>
#include<string.h>
int main()
{
	char str[50],temp;
	int i = 0;
	int j;
	fgets(str,50,stdin);
	j = strlen(str) - 1;
	while(i<j)
	{
		temp=str[i];
		str[i]=str[j];
		str[j]=temp;
		i++;
		j--;
	}
	printf("%s",str);
	return 0;
}

Explanation

initialize i to first location of string and j to last location of string using
i=0
j=n-1

swap the characters in location i and j, then increment i by 1 and decrement j by 1.
t=str[i]
str[i]=str[j]
str[j]=temp

repeat the above step till i is less than j