Answers for "How to reverse string in algorithm"

0

Reverse a string

function reverseString(str) {
    return str.split('').reverse().join('');
}

reverseString('string');    // "gnirts"
Posted by: Guest on June-30-2021
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 "How to reverse string in algorithm"

Code answers related to "Javascript"

Browse Popular Code Answers by Language