mayap

GetFourDigitsOfNumber - FunctionsWithThem

Apr 11th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace FourDigitNumber
  8. {
  9.     class FourDigitNum
  10.     {
  11.         static void Main()
  12.         {
  13.             int num;
  14.             Console.WriteLine("Enter a four-digit number: ");
  15.             num = int.Parse(Console.ReadLine());
  16.  
  17.             int firstDigit = num % 10;
  18.             int secondDigit = num / 10 % 10;
  19.             int thirdDigit = num / 100 % 10;
  20.             int fourthDigit = num / 1000 % 10;
  21.  
  22.             int sumDigits = firstDigit + secondDigit + thirdDigit + fourthDigit;
  23.             Console.WriteLine("The sum of the digits is: " + sumDigits);
  24.  
  25.             Console.WriteLine("The number in reversed order is: " + firstDigit + secondDigit + thirdDigit + fourthDigit);
  26.  
  27.             Console.WriteLine("When the last digit is on first position: " + firstDigit + thirdDigit + secondDigit + fourthDigit);
  28.  
  29.             Console.WriteLine("When exchanging the second and third digits: " + fourthDigit + secondDigit + thirdDigit + firstDigit);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment