Advertisement
Fundamentalen

FourDigitNumber

Mar 14th, 2014
2,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2.  
  3. class FourDigitNumber
  4. {
  5.     static void Main()
  6.     {
  7.         Console.Write("Enter your number: ");
  8.         int number = int.Parse(Console.ReadLine());
  9.  
  10.         //fourth digit
  11.         int firstDigit = number % 10;
  12.  
  13.         //third digit
  14.         int restNumberTwo = number / 10;
  15.         int secondDigit = restNumberTwo % 10;
  16.  
  17.         //second digit
  18.         int restNumberThree = number / 100;
  19.         int thirdDigit = restNumberThree % 10;
  20.  
  21.         //first digit
  22.         int restNumberFour = number / 1000;
  23.         int fourthDigit = restNumberFour % 10;
  24.  
  25.         Console.WriteLine("Number " + number);
  26.         Console.WriteLine("Sum of digits "+ (firstDigit + secondDigit + thirdDigit + fourthDigit));
  27.         Console.WriteLine("Reversed {0}{1}{2}{3}", firstDigit, secondDigit, thirdDigit, fourthDigit);
  28.         Console.WriteLine("Last digit in front {0}{1}{2}{3}", firstDigit, fourthDigit, thirdDigit, secondDigit);
  29.         Console.WriteLine("Second and third digits exchanged {0}{1}{2}{3}", fourthDigit, secondDigit, thirdDigit, firstDigit);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement