w3resource
C# Sharp Programming Exercises

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?



New Content: Composer: Dependency manager for PHP, R Programming