Advertisement
grubcho

Nth number

Jun 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 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 nth_digit
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int number = int.Parse(Console.ReadLine());
  14.             int index = int.Parse(Console.ReadLine());
  15.             Console.WriteLine(FindNthDigit(number, index));
  16.         }
  17.         static int FindNthDigit(int number, int index)
  18.         {
  19.             int currentIndex = 0;
  20.             int currentNumber = 0;
  21.             while (number > 0)
  22.             {
  23.                 currentIndex++;
  24.                 if (currentIndex == index)
  25.                 {
  26.                     currentNumber = number % 10;
  27.                    
  28.                 }
  29.                 else
  30.                 {
  31.                     number = number / 10;
  32.                 }
  33.             }
  34.             return currentNumber;
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement