Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Print a string in reverse order

C# Sharp For Loop: Exercise-57 with Solution

Write a program in C# Sharp to print a string in reverse order.

C# Sharp: Print a string in reverse order

Sample Solution:-

C# Sharp Code:

using System;  
public class Exercise57
{  
    public static void Main()
        {
            string str, str1 = ""; 
            int i,l;
			
			
	Console.Write("\n\n");
    Console.Write("Print a string in reverse order:\n");
    Console.Write("----------------------------------");
    Console.Write("\n\n");				

            Console.Write("Input  A String : ");
            str = Console.ReadLine();

            l = str.Length-1;
            for (i=l;i>=0;i--)
            {

                str1 = str1 + str[i];
                

            }

            Console.WriteLine("The string in Reverse  Order Is : {0}", str1);
            Console.Write("\n");	

        }
}

Sample Output:

Print a string in reverse order:                                                                            
----------------------------------                                                                          
Input  A String : W3RESOURCE                                                                                
The string in Reverse  Order Is : ECRUOSER3W 

Flowchart:

Flowchart: Print a string in reverse order

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to Check Whether a Number can be Express as Sum of Two Prime Numbers.
Next: Write a C#Sharp program to display alphabet pattern like 'A' with an asterisk.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.