C语言,输入一个正整数,按由大到小的顺序输出它的所有质数的因子(如180=5*3*3*2*2)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 long num; 7 8 while(cin >> num){ 9 if(num == 1){ 10 cout << num << endl; 11 continue; 12 } 13 14 for(int i = 2; i <= num; ++i){ 15 if(num%i == 0){ 16 num = num/i; 17 cout << i << " "; 18 i--;//遇到一个质数,那么该质数可能会被整除多次 19 } 20 } 21 cout << endl; 22 } 23 24 return 0; 25 }