Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. namespace _02._Convert_from_base_N_to_base_10
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] ns = Console.ReadLine().Split();
  11.             BigInteger baseN = BigInteger.Parse(ns[0]);
  12.             BigInteger num = BigInteger.Parse(ns[1]);
  13.             Console.WriteLine(ConvertToBase10(num, baseN));
  14.         }
  15.  
  16.         static BigInteger ConvertToBase10(BigInteger num, BigInteger baseN)
  17.         {
  18.             BigInteger result = new BigInteger();
  19.  
  20.             int i = 0;
  21.             while (num > 0)
  22.             {
  23.                 BigInteger n = num % 10;
  24.                 result += n * BigInteger.Pow(baseN, i);
  25.  
  26.                 i++;
  27.                 num /= 10;
  28.             }
  29.  
  30.             return result;
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement