reverse elents in string code example
Example 1: code to reverse a string
#include <stdio.h>
#include <string.h>
int main()
{
char s[100];
printf("Enter a string to reverse\n");
gets(s);
strrev(s);
printf("Reverse of the string: %s\n", s);
return 0;
}
Example 2: reverse the string
#!/bin/bash
input="$1"
reverse=""
len=${#input}
for (( i=$len-1; i>=0; i-- ))
do
reverse="$reverse${input:$i:1}"
done
echo "$reverse"