质因数 Virus

// aa.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "iostream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 int a,b,d,e,i,j=0;
    int c[10000];
    cin>>a;
    e=a;
   
    for(i=2;i<=a;i++)
    {
       b=a%i;
       if(b==0)
       {
         if(a!=i)
         {
           c[j]=i;
           j=j+1;
           a=a/i;
           i=1;
         }
         if(a==i)
         {
           if(j==0)
           {
             cout<<"sorry!"<<'\n';
             break;
           }
           if(j!=0)
           {
              c[j]=a;
              cout<<e<<"=";
              for(d=0;d<j;d++)
              {
                 cout<<c[d]<<"×";
              }
               cout<<c[j]<<'\n';
                break;
           }
         }
       }
    }
   
    system("PAUSE");
 return 0;
}

【Blog】http://virusswb.cnblogs.com/

【MSN】jorden008@hotmail.com

【说明】转载请标明出处,谢谢

反馈文章质量,你可以通过快速通道评论:

原文地址:https://www.cnblogs.com/virusswb/p/1061417.html