using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace stack
{
class stack
{
static int[] s;
static int top;
static void Init(int n)
{
s = new int[n];
top = -1;
}
static bool isEmpty()
{
return top == -1;
}
static bool isFull()
{
return top >= s.Length - 1;
}
static void Push(int x)
{
if (isFull())
Console.WriteLine("stack day");
else s[++top] = x;
}
static int Pop()
{
if (isEmpty())
throw new Exception("stack rong");
else
return s[top--];
}
static void Main(string[] args)
{
int n;
Console.Write("nhap so can doi:");
n = int.Parse(Console.ReadLine());
Init(n);
string st = "0123456789ABCDEF";
Console.Write("nhap he can chuyen:");
int k = int.Parse(Console.ReadLine());
while (n != 0)
{
Push((int)st[n % k]);
n = n / k;
}
Console.Write("ket qua chuyen sang he thap luc phan la:");
while (!isEmpty())
{
Console.Write((char)Pop());
}
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace stack
{
class stack
{
static int[] s;
static int top;
static void Init(int n)
{
s = new int[n];
top = -1;
}
static bool isEmpty()
{
return top == -1;
}
static bool isFull()
{
return top >= s.Length - 1;
}
static void Push(int x)
{
if (isFull())
Console.WriteLine("stack day");
else s[++top] = x;
}
static int Pop()
{
if (isEmpty())
throw new Exception("stack rong");
else
return s[top--];
}
static void Main(string[] args)
{
int n;
Console.Write("nhap so can doi:");
n = int.Parse(Console.ReadLine());
Init(n);
string st = "0123456789ABCDEF";
Console.Write("nhap he can chuyen:");
int k = int.Parse(Console.ReadLine());
while (n != 0)
{
Push((int)st[n % k]);
n = n / k;
}
Console.Write("ket qua chuyen sang he thap luc phan la:");
while (!isEmpty())
{
Console.Write((char)Pop());
}
Console.ReadKey();
}
}
}