Guest User

Untitled

a guest
Apr 11th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 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.             long num = long.Parse(Console.ReadLine());
  14.             int index = int.Parse(Console.ReadLine());
  15.             getIndex(num, index);
  16.         }
  17.  
  18.         static long getIndex(long num, int index)
  19.         {
  20.             int n = 1;
  21.             while (num > 0)
  22.             {
  23.  
  24.                 var current = num % 10;
  25.                 if (n == index)
  26.                 {
  27.                     Console.WriteLine(current);
  28.                 }
  29.                 else
  30.                 {
  31.                     num = num / 10;
  32.                 }
  33.                 n++;
  34.             }
  35.             return num;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment