#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str[10],temp;
int i,len;
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
temp=str[i];
str[i]=str[len];
str[len--]=temp;
}
printf("%s",str);
getch();
}
Please do give your views on this.
With Regards,
Sumit Ranjan.
Analyst at RMSI Company.
To reverse a number, first convert the number to a string, then reverse the string. Given your number consists of alphanumeric characters, the number must already be a string so simply reverse the string: #include<string> using std::string; string reverse (const string& s) { string str {}; for (auto c : s) str.insert (str.begin(), c); return str; } int main () { std::cout << "Enter a number: "; string s {}; std::cin >> s; std::cout << "The number in reverse is: " << reverse (s); }
there is no such method using string copy
You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.
(in C#)string Reverse (string input) {There are two cases; the recursive case and the trivial case.The trivial case is when the string has zero or one character. In this case, the reversal of the string is the same.if (input.Length
Sure, recursion can always be substituted with using a stack.
To reverse a number, first convert the number to a string, then reverse the string. Given your number consists of alphanumeric characters, the number must already be a string so simply reverse the string: #include<string> using std::string; string reverse (const string& s) { string str {}; for (auto c : s) str.insert (str.begin(), c); return str; } int main () { std::cout << "Enter a number: "; string s {}; std::cin >> s; std::cout << "The number in reverse is: " << reverse (s); }
shashi
no answer....pls post
there is no such method using string copy
By writing user defined function.
You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.
Yes, you can use regex to determine if a given string is a palindrome by reversing the string and then comparing it to the original string using regex.
There are five common methods of string inversion in Python: using string slicing, using recursion, using the list reverse () method, using stack and using for loop. Use string slicing (most concise) s = "hello" reversed_ s = s[::-1] print(reversed_s) >>> olleh Use recursive def reverse_ it(string): if len(string)==0: return string else: return reverse_ it(string[1:]) + string[0] print "added " + string[0] string1 = "the crazy programmer" string2 = reverse_ it(string1) print "original = " + string1 print "reversed = " + string2 Use the list reverse() method in [25]: l = ['a', 'B', 'C','d '] ...: l.reverse() ...: print (l) ['d', 'c', 'b', 'a'] Using stack def Rev_ string(a_string): L = list (a_string) # simulate all stacking new_ string = "" while len(l)>0: new_ String + = l.pop() # simulate stack out return new_ string Use the for loop #for loop def func(s): r = "" max_ index = len(s) - 1 for index,value in enumerate(s): r += s[max_index-index] return r r = func(s) The above are the five common methods of string inversion in Python. I hope it can be helpful to your learning of Python strings
(in C#)string Reverse (string input) {There are two cases; the recursive case and the trivial case.The trivial case is when the string has zero or one character. In this case, the reversal of the string is the same.if (input.Length
Sure, recursion can always be substituted with using a stack.
The following codes only applied to unsigned integers: public int Reverse(int inputNumber) { string inputString = inputNumber.ToString(); string reversed = StringUtil.Reverse(inputString); return int.Parse(reversed); } public class StringUtil { // returns a reversed string from the given one public static string Reserve(string originalString) { StringBuilder sb = new StringBuilder(); char[] charArray = originalString.ToCharArray(); for (int i = charArray.Length - 1; i >= 0; i--) { sb.Append(charArray[i]); } return sb.ToString(); } }
pata nhe