Reverse String C – Program

Reverse String C – Program

Write a c program to display reverse string of given string.

#include<stdio.h>

int main()
{
 char str[100];
 int i,j;
 char temp;
 printf("Please enter the string = ");
 gets(str); 

 for(i=0;str[i];i++)
 {
    for(j=0,i--;j<i;j++,i--)
   {
      temp=str[i];
      str[i]=str[j];
      str[j]=temp;
   }
 }

 printf("The reversed string is =  %s",str);

 return 0;
}

The Reverse String C Program output is :

Please enter the string = meeraacademy

The reversed string is = ymedacaareem

 

Author: Meera Academy

Leave a Reply

Your email address will not be published. Required fields are marked *