Advertisement
Guest User

Systemy pozycyjne

a guest
Dec 13th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 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 Problem30
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int t = int.Parse(Console.ReadLine());
  14.             for (int i = 0; i < t; i++)
  15.             {
  16.                 int n = int.Parse(Console.ReadLine());
  17.                 Console.WriteLine(Zamien(n, 16));
  18.                 Console.WriteLine(" ");
  19.                 Console.WriteLine(Zamien(n, 11));
  20.             }
  21.         }
  22.  
  23.         private static string Zamien(int n, int podstawa)
  24.         {
  25.             char[] tab = new char[50];
  26.             char[] znaki = "0123456789ABCDEF".ToCharArray();
  27.             int index = 0;
  28.             for (; n != 0; n /= podstawa)
  29.             {
  30.                 tab[index++] = znaki[n % podstawa];
  31.             }
  32.             string tekst = "";
  33.             for (int i = 0; i < tab.Length && tab[i] != 0; i++)
  34.             {
  35.                 tekst = tab[i] + tekst;
  36.             }
  37.             return tekst;
  38.         }
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement