w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: Display the number in reverse order

C# Sharp For Loop: Exercise-37 with Solution

Write a program in C# Sharp to display the number in reverse order.

Pictorial Presentation:

C# Sharp Exercises: Display the number in reverse order

Sample Solution:

C# Sharp Code:

using System;  
public class Exercise37 
{  
    public static void Main()
{
    int num,r,sum=0,t;
	
	Console.Write("\n\n");
    Console.Write("Display the number in reverse order:\n");
    Console.Write("--------------------------------------");
    Console.Write("\n\n");  	
	

    Console.Write("Input a number: ");
    num = Convert.ToInt32(Console.ReadLine()); 	

    for(t=num;t!=0;t=t/10)
	{
         r=t % 10;
         sum=sum*10+r;
    }
Console.Write("The number in reverse order is : {0} \n",sum);
  }
}

Sample Output:

Display the number in reverse order:                                                                        
--------------------------------------                                                                      
Input a number: 25                                                                                          
The number in reverse order is : 52  

Flowchart:

Flowchart : Display the number in reverse order

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to display the such a pattern for n number of rows using a number which will start with the number 1 and the first and a last number of each row will be 1.
Next: Write a program in C# Sharp to check whether a number is a palindrome or not.

What is the difficulty level of this exercise?



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