## 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;
}```

We are Teaching "Web Development using Python" through Online.

View Tutor Profile and Course Syllabus

### 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 ```

#### Author - Ramesh P Natarajan

Software Developer and Technology Trainer, very much passionate in the field of Software Application Development, Machine Learning and Search Engine Optimization.

Write to: [email protected]

### Interesting Pattern Programs: for more Patterns

```Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution```
```Input:
5
Output:
*
***
*****
*******
*********
*******
*****
***
*Solution```
```Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution```
```Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution```
```Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution```
```Input:
5
Output:
*********
*******
*****
***
*
***
*****
*******
*********Solution```