Results 1 to 4 of 4

Thread: Programming logic to print word in reverse order in C#

  1. #1
    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..

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Programming logic to print word in reverse order in C#

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

    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();

    }

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    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:

    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;
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    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.

    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......

Similar Threads

  1. Need help to reverse the name order in Microsoft Excel
    By Kesar in forum MS Office Support
    Replies: 3
    Last Post: 24-01-2012, 02:16 PM
  2. How to Reverse Row Order in Microsoft Excel
    By Raju Chacha in forum MS Office Support
    Replies: 1
    Last Post: 14-01-2012, 06:25 PM
  3. How to reverse Page Order in Acrobat Pro 9
    By Patricia-USA in forum Windows Software
    Replies: 5
    Last Post: 13-07-2010, 06:38 AM
  4. How to print reverse image in word
    By Visala in forum Windows Software
    Replies: 3
    Last Post: 04-08-2009, 01:26 PM
  5. How to reverse print order in Word 2007??
    By NavinS in forum MS Office Support
    Replies: 1
    Last Post: 23-01-2008, 12:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,749,882,129.04082 seconds with 16 queries