C program to reverse a given string

Complete C program to reverse a given string

#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
char str[100], reverse_str[100], temp;
int i=0, j=0;
clrscr();
printf("\n Enter the string : ");
gets(str);
j=strlen(str)ā€“1;
while(i<j)
{
 temp = str[j];
str[j] = str[i];
 str[i] = temp;
 i++;
jā€“ā€“;
}
printf("\n The reversed string is : ");
puts(str);
getch();
return 0;
}

Output

Enter the string: Hi there
The reversed string is: ereht iH

Leave a Comment