how to display number in reversed

Posted by Gow.net under C# on 2/10/2012 | Points: 10 | Views : 756 | Status : [Member] | Replies : 6
how to display number in reversed?

input:1234567890
output:0987654321

gowthaman8870226416


Responses

Posted by: Majith on: 2/10/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

There are many ways to print the above output,use the below code,

string inp = "1234567890";

char[] outp = inp.ToCharArray();
Array.Reverse(outp);
foreach (var item in outp)
{
Response.Write(item);
}

Regards ,
Majith

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gow.net on: 2/11/2012 [Member] Starter | Points: 25

Up
0
Down
hi Majith sir

please tech me other way to reverse number


gowthaman8870226416

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/11/2012 [Member] Silver | Points: 25

Up
0
Down
string inp = "1234567890";
string result = string.Empty ;
for (int i = inp.Length-1; i >= 0; i--)
{
result = result + inp[i];
}
Response.Write("Reversed value is:"+result );

Thanks,
Sanjay

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vahidbakhtiary on: 2/12/2012 [Member] Starter | Points: 25

Up
0
Down
hi
use of this code :
string text = "1234567890";
int CountLenght = text.Count();

for (int i = CountLenght-1; CountLenght >= 0; i--)
{
MessageBox.Show(text[i].ToString());
}
i hope helpful.

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/12/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Vahidbakhtiary ,
If you put MessageBox.Show inside the loop , it will be repeatedly show message.
so you need to store the result in another variable inside the loop and then you can use the same outside the loop to show the entire reversed string once.

Thanks,
Sanjay

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhisekjani on: 2/12/2012 [Member] Starter | Points: 25

Up
0
Down
string abc = "1234567890";
string result = string.Empty ;
for (int i = abc.Length-1; i >= 0; i--)
{
result = result + inp;
}
Response.Write("Reversed value is:"+result );

Thanks,
Abhisek

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response