-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path_09_BasicOperationsQuestion15.cs
38 lines (31 loc) · 1.05 KB
/
_09_BasicOperationsQuestion15.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* 15. Read an integer number with 6 digits and generate a new number with the digits in reverse order
*/
using System;
class _006_BasicOperationsQuestions15
{
public static void Main(string[] args)
{
Console.Write("Type a number with 6 digits: ");
int number = Convert.ToInt32(Console.ReadLine());
int invertedNumber = 0;
int lastDigit = number % 10;
invertedNumber = lastDigit;
int numberAux = number / 10;
lastDigit = numberAux % 10;
invertedNumber = invertedNumber * 10 + lastDigit;
numberAux = numberAux / 10;
lastDigit = numberAux % 10;
invertedNumber = invertedNumber * 10 + lastDigit;
numberAux = numberAux / 10;
lastDigit = numberAux % 10;
invertedNumber = invertedNumber * 10 + lastDigit;
numberAux = numberAux / 10;
lastDigit = numberAux % 10;
invertedNumber = invertedNumber * 10 + lastDigit;
numberAux = numberAux / 10;
lastDigit = numberAux % 10;
invertedNumber = invertedNumber * 10 + lastDigit;
Console.WriteLine($"Inverted number: {invertedNumber}");
}
}