分解质因数

private static void 分解质因数()        

{          

   StringBuilder sb = new StringBuilder();   

          int n,inputNumb;     

        Console.WriteLine("please input a number:");  

           inputNumb = Convert.ToInt32(Console.ReadLine());    

         n = inputNumb;

            for (int i = 2; i <= n; i++) //循环被除数     

        {               

  while (n != i)           

      {               

      if (n % i == 0) //整除即可//质数            

         {            

             sb.Append(i+"*");          

               n = n / i; //新的除数        

             }           

          else break;      

           }      

       }        

     sb.Append(n);    

         Console.WriteLine("{0}分解质因数为:{1}",inputNumb,sb.ToString().TrimEnd(new char[]{'*'}));    

     }

posted @ 2013-01-05 18:20  程序有Bug  阅读(221)  评论(0编辑  收藏  举报