Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-11-2009
Member
 
Join Date: May 2008
Posts: 72
Programming logic to print word in reverse order in C#

I am new in the field of programming.and I don't have strong programming logic.
I was trying to code program in C# to print word which we provide in the reverse order but I was not successful.

For example, suppose If you pass string "COMPUTER" then output should be "RETUPMOC".

Please provide me the code or logic to write this program..
Reply With Quote
  #2  
Old 18-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Programming logic to print word in reverse order in C#

Have you tried below program?....This program run successfully when I executed:

Quote:
class Program
{
static void Main(string[] args)
{
string str = "COMPUTER";
char[] chararray = str.ToCharArray();
int length = chararray.GetLength(0);
for (int i = 0; i <= length / 2; i++, length--)
{
char x;
x = str[i];
chararray[i] = chararray[length-1];
chararray[length-1] = x;

}
Console.WriteLine("{0}",new string(chararray).ToUpper());

Console.ReadLine();

}
Reply With Quote
  #3  
Old 18-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Programming logic to print word in reverse order in C#

Hi friend,

TO print word in reverse order first you have to find the length of the word which you provides.

See following:

Quote:
string word = "COMPUTER";
for (int i = 0; i < = word.Length/2; i++)
{
char c = word[i];
word[i] = word[word.Length - 1 - i];
word[word.Length - 1 - i] = c;
}
Reply With Quote
  #4  
Old 18-11-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Programming logic to print word in reverse order in C#

Using below C# program show the word in reverse order.This program take input from user ,then reverse it and finally displays on the screen.

Quote:
class Program
{
public static void Main()
{
string a;
Console.WriteLine("enter the word u want to display in reverse order");
a = Console.ReadLine();
string StrName = a;
int i;
String reverse1 = "";
String reverse2 = "";

for (i = 0; i < StrName.Length; i++)
{

reverse1 = StrName[StrName.Length - 1 - i].ToString();
reverse2 = reverse2 + Show;


}

Console.WriteLine(reverse2);
}
}
Please try this above program......
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Programming logic to print word in reverse order in C#"
Thread Thread Starter Forum Replies Last Post
Need help to reverse the name order in Microsoft Excel Kesar MS Office Support 3 24-01-2012 02:16 PM
How to Reverse Row Order in Microsoft Excel Raju Chacha MS Office Support 1 14-01-2012 06:25 PM
How to reverse Page Order in Acrobat Pro 9 Patricia-USA Windows Software 5 13-07-2010 06:38 AM
How to print reverse image in word Visala Windows Software 3 04-08-2009 01:26 PM
How to reverse print order in Word 2007?? NavinS MS Office Support 1 23-01-2008 12:47 AM


All times are GMT +5.5. The time now is 01:59 AM.