Reverse the given String
Get a String and reverse the characters of the string
Sample Input 1:
Hello
Sample Output 1:
olleH
Try your Solution
Strongly recommended to Solve it on your own, Don't directly go to the solution given below.
#include<stdio.h>
int main()
{
//write your code here
}
Program or 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;
}
Program 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
Comments
Related Programs
- Print the characters of String with space
- Find the Length of given String
- Find the location of given Character in a String
- Count the occurences of given Character in a String
- Covert Lowercase characters to Uppercase Characters
- Covert Uppercase characters to Lowercase Characters
- Count the number of vowels in given string
- Compare two Strings are equal
- Concate two given Strings
- Find the location of given sub string in a String
- Count the occurences of given substring in a String
- Check the given string is Palindronme
- Remove the spaces in given String
- Remove the Vowels in given String
coming Soon
coming Soon