Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FourDigitNumber
- {
- class FourDigitNum
- {
- static void Main()
- {
- int num;
- Console.WriteLine("Enter a four-digit number: ");
- num = int.Parse(Console.ReadLine());
- int firstDigit = num % 10;
- int secondDigit = num / 10 % 10;
- int thirdDigit = num / 100 % 10;
- int fourthDigit = num / 1000 % 10;
- int sumDigits = firstDigit + secondDigit + thirdDigit + fourthDigit;
- Console.WriteLine("The sum of the digits is: " + sumDigits);
- Console.WriteLine("The number in reversed order is: " + firstDigit + secondDigit + thirdDigit + fourthDigit);
- Console.WriteLine("When the last digit is on first position: " + firstDigit + thirdDigit + secondDigit + fourthDigit);
- Console.WriteLine("When exchanging the second and third digits: " + fourthDigit + secondDigit + thirdDigit + firstDigit);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment