25 lines
616 B
C#
25 lines
616 B
C#
using System.Collections;
|
|
namespace Lesson2_Stack练习题
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Console.Write("输入一个数字:");
|
|
int num = int.Parse(Console.ReadLine());
|
|
Stack bio = new Stack();
|
|
while (num != 0)
|
|
{
|
|
int r = num % 2;
|
|
bio.Push(r);
|
|
num /= 2;
|
|
}
|
|
Console.Write("你输入的数字二进制为:");
|
|
while (bio.Count > 0)
|
|
{
|
|
Console.Write(bio.Pop());
|
|
}
|
|
}
|
|
}
|
|
}
|