Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class FourDigitNumber
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Please enter \"abcd\" - Four-Digit Number");
- int number = int.Parse(Console.ReadLine());
- bool hasFourDigits = (number.ToString().Length == 4);
- while (!hasFourDigits)
- {
- Console.WriteLine("Please write a four-digit number:");
- number = int.Parse(Console.ReadLine());
- hasFourDigits = (number.ToString().Length == 4);
- }
- int a = (number / 1000) % 10;
- int b = (number / 100) % 10;
- int c = (number / 10) % 10;
- int d = number % 10;
- Console.Write("The sum of the digits of the number you have just entered is : ");
- Console.WriteLine(a + b + c + d);
- Console.WriteLine("Print on the console the number in reversed order: {0}{1}{2}{3}", d, c, b, a);
- Console.WriteLine("Puts the last digit in the first position: {0}{1}{2}{3}", d, a, b, c);
- Console.WriteLine("Exchanges the second and the third digits: {0}{1}{2}{3}", a, c, b, d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement