Tisho_Todorov

06.FourDigitNumber

Oct 12th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2.  
  3. class FourDigitNumber
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("Please give us a four-digit number");
  8.         Console.Write("your number : ");
  9.         int number = int.Parse(Console.ReadLine());
  10.        
  11.         // fourth digit
  12.         int firstDigit = number % 10;
  13.        
  14.         // third digit
  15.         int restNumberTwo = number / 10;
  16.         int secondDigit = restNumberTwo % 10;
  17.        
  18.         // second digit
  19.         int restNumberThree = number / 100;
  20.         int thirdDigit = restNumberThree % 10;
  21.        
  22.         // first digit
  23.         int restNumberFour = number / 1000;
  24.         int fourthDigit = restNumberFour % 10;
  25.  
  26.         Console.WriteLine("Your number is : " + number);
  27.         Console.WriteLine("The sum of digits is : " + (firstDigit + secondDigit + thirdDigit + fourthDigit));
  28.         Console.WriteLine("Digits were reversed {0}{1}{2}{3}" ,firstDigit ,secondDigit ,thirdDigit ,fourthDigit);
  29.         Console.WriteLine("Last digit go at front {0}{1}{2}{3}" ,firstDigit ,fourthDigit ,thirdDigit ,secondDigit);
  30.         Console.WriteLine("Second and third digits exchanged {0}{1}{2}{3}" ,fourthDigit ,secondDigit ,thirdDigit ,firstDigit);
  31.         Console.WriteLine("Enjoy yourself - see you !");
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment