reverse string

Discussion in 'C' started by senthil_a4nlabs, Aug 29, 2016.

  1. senthil_a4nlabs

    senthil_a4nlabs New Member

    Joined:
    Aug 27, 2016
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    give me the c prograame for reverse string
     
  2. persysweb

    persysweb Member

    Joined:
    Aug 1, 2017
    Messages:
    98
    Likes Received:
    18
    Trophy Points:
    8
    Location:
    India
    Home Page:
    httpS://persys.in/
    Hi,
    Here is the C program for reversing a string

    Code:
    #include<stdio.h>
    #include<string.h>
     
    int main() {
       char str[100], temp;
       int i, j = 0;
     
       printf("\nEnter the string :");
       gets(str);
     
       i = 0;
       j = strlen(str) - 1;
     
       while (i < j) {
          temp = str[i];
          str[i] = str[j];
          str[j] = temp;
          i++;
          j--;
       }
     
       printf("\nReverse string is :%s", str);
       return (0);
    }
    
    Output :
    Enter the string  : Neha
    Reverse string is : aheN
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice