Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class FourDigitNumber
- {
- static void Main()
- {
- Console.WriteLine("Enter a four-digit number to see some \"magic\" with it.");
- Console.WriteLine("The number musn't start with 0.");
- Console.WriteLine();
- Console.Write("Your number: ");
- string inputNum = Console.ReadLine();
- int number = int.Parse(inputNum);
- if (inputNum.Length > 4)
- {
- Console.WriteLine("The input number is more than 4 digits long! Try again.");
- return;
- }
- int a = number / 1000;
- a %= 10;
- int b = number / 100;
- b %= 10;
- int c = number / 10;
- c %= 10;
- int d = number % 10;
- if (a == 0)
- {
- Console.WriteLine("The number musn't start with 0! Try again.");
- return;
- }
- int sumOfDigits = a + b + c + d;
- Console.WriteLine("The sum of the digits is {0}", sumOfDigits);
- Console.WriteLine("Your number in reversed order is " + d + c + b + a);
- Console.WriteLine("Your number with last digit in front is " + d + a + b + c);
- Console.WriteLine("Your number with second and third digits exchanged is " + a + c + b + d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement