Advertisement
YavorGrancharov

Nth_Digit

Jun 14th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 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 num = int.Parse(Console.ReadLine());
  14.             int index = int.Parse(Console.ReadLine());
  15.  
  16.             int result = FindNthDigit(num, index);
  17.             Console.WriteLine(result);
  18.         }
  19.  
  20.         static int FindNthDigit(int num, int index)
  21.         {
  22.             int count = 0;
  23.             int digit = 0;
  24.  
  25.                 while (num - 1 != 0)
  26.                 {
  27.                 digit = num % 10;
  28.                 count++;
  29.                     if (count == index)
  30.                     {
  31.                         return digit;
  32.                     break;
  33.                     }
  34.                         num = num / 10;
  35.                 }
  36.             return FindNthDigit(num, index);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement