In this post, we will learn how to reverse a string in C language.
For example - If the string is "hello" then, the output is "olleh".
IMPLEMENTATION -
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
char str [100];
char rev [100];
printf("Enter a string:\t");
scanf("%s", str);
printf("The original string is %s\n", str);
for(i = 0; str[i] != '\0'; i++);
{
k = i-1;
}
for(j = 0; j <= i-1; j++)
{
rev[j] = str[k];
k--;
}
printf("The reverse string is %s\n", rev);
getch();
}
OUTPUT:
Enter a string: ProgrammersDoor
The original string is ProgrammersDoor
The reverse string is rooDsremmargorP
Happy Coding!
Follow us on Instagram @programmersdoor
Join us on Telegram @programmersdoor
Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem.
Follow Programmers Door for more.
Comments