Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace OperationsWithFourDigitNum
- {
- class OperationsWithFourDigitNum
- {
- static void Main()
- {
- Console.WriteLine("Enter a random four digit number: ");
- int number = int.Parse(Console.ReadLine());
- //detach the four digits; convert them into whole numbers
- int a = number / 1000;
- int b = (number - a * 1000) / 100;
- int c = (number - (a * 1000 + b * 100)) / 10;
- int d = (number - (a * 1000 + b * 100 + c * 10));
- //calculations
- int sum = a + b + c + d;
- //console outpute
- Console.WriteLine("The sum of the four digits is: " + sum);
- Console.WriteLine("Reverse order: {0}{1}{2}{3}", d, c, b, a);
- Console.WriteLine("Last digit in first place: {0}{1}{2}{3}", d, a, b, c);
- Console.WriteLine("Switched 2nd and 3rd positions: {0}{1}{2}{3}", a, c, b, d);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement