Answers for "Write an Algorithm to reverse a string without using any built-in function."

C
0

Write an Algorithm to reverse a string without using any built-in function.

#include <stdio.h>
 
int main() {
 
       char str[100],  temp;
       int i, j = -1;
 
       // Take string input from user. 
   
       printf("Enter string");
       gets(str);
 
       i = 0;
  
       // count the length of a input string. 
   
       while(str[++j]!='\0');
   
        j = j - 1;
 
      /* Swap the positions of an element. */
  
      while (i < j) {
          temp = str[i];
          str[i] = str[j];
          str[j] = temp;
          i++;
          j--;
    }
 
     printf("Reverse of a input string is :%s", str);
     return (0);
}
Posted by: Guest on June-29-2021

Code answers related to "Write an Algorithm to reverse a string without using any built-in function."

Code answers related to "C"

Browse Popular Code Answers by Language