分解质因数程序(C++)


#include<iostream>
#include<iomanip>
#include<string>
#include <stdlib.h>
using namespace std;
void Analyze();
void figure(long n);
double transformer(string& s);

double transformer(string& s)
{
     while(s.find(",") != string::npos) {
           s.erase(s.find(","), 1);
      }
     return atof(s.c_str());
}

void Analyze_And_Input()
{
     double transformer(string&);
     static int m=0;
     string (q);
     cout<<"输入数据(类型为 long)程序将分解质因数,输入0可退出。/n"<<endl;
     cin>>q;
     if(m>2){system("cls");cout<<"Compiled By:Ms"<<endl;m=0;}
      m++;
      double temp1=transformer(q);
      if (temp1==0.618){cout<<"Life is brilliant!/n/n/n/nHowever, "; cin.get();}
      if (temp1==-0.618){cout<<"SB Andy!/n/n/n/nHowever, "; cin.get();}
      if (temp1==3.14){cout<<"Pi is beatiful!/n/n/n/nHowever, "; cin.get();}
      if (temp1==2.718){cout<<"e:Nature is maganificant!/n/n/n/nHowever, "; cin.get();}
       double transformer(string&);
       string num("1234567890");
       string::size_type pos=0;
       while((q.find_first_not_of(num,pos))!=string::npos)//看其中是否有非数字成分
       {
        cout<<"您的输入不是符合条件的正整数!/n"<<endl;
        ++pos;
        cin.get();
        Analyze_And_Input();
       }
       double transformer(string&);
     double temp=transformer(q);
     long n;
     n=(long)temp;
     if(n==0) exit(0);
     if(n<=1)
     {
             cout<<"Error 输入数据必须大于等于1!/n"<<endl;
             cin.get();
             Analyze_And_Input();
     }
    
     else {figure(n);}
}
     
void figure(long n)
{
int count=0;
long t=0;
cout<<n<<"="<<" ";
for(long i=2;i<=n;i++)
{
t=n%i;
if(t==0)
 {
 n=n/i;
 cout<<i;
if(i<=n-1)
 cout<<" * ";
 i--;
 count++;
 if(count%5==0)
   cout<<"          "<<endl;
 }
}
 cout<<"/n输入数据的质因数有"<<count<<"个。/n"<<endl;
 cin.get();
 Analyze_And_Input();
}

int main()
{

 Analyze_And_Input();
 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值