C#將十進製轉二進製
using System; class ggg { static void Main() { Console.WriteLine("請你輸入十進製,我為你轉換成二進製,謝謝使用。"); int a,b,d,f; int c=0; a=int.Parse(Console.ReadLine()); b=a; do { b/=2; c=++c; } while(b!=1); d=c+1; f=c; int[] A=new int[d]; for(int i=c;i>0;i--) { A[i]=(int)a%2; a/=2; } A[0]=1; for(int j=0;j<=f;j++) { Console.Write(A[j]); } Console.WriteLine("/n"+"歡迎 使用,謝謝退出!"); System.Threading.Thread.Sleep(3000); } }
最後更新:2017-04-02 04:00:24