#include <iostream>
using namespace std;
void sort(int a);//建立分解函数
int main()
{
int number;
cout << "输入待分解的数:";
cin >> number;
sort(number);
return 0;
}
void sort(int a)
{
int temp=0;
if (a == 1)
cout << "该数没有质因数!"<<endl;
else
for (int i = 2; i <= a; i++)
{
if (a%i == 0)
{
cout << "第" << temp + 1 << "个质因数是:" << i << endl;
a /= i;
temp++;
}
}
cout << "分解结束!!";
}
C++分解质因数
最新推荐文章于 2024-06-15 09:39:57 发布