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:
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:
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?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework