写的比较乱。
#include <iostream> using namespace std; int* gene(int); int main() { cout << "Please enter the num you want to get it yizi: "; int num ; cin >> num; int* yiziarray; yiziarray= gene(num); int index = 0; cout << num << " = "; while (*(yiziarray+index )) { cout << *(yiziarray+index ) ; index ++; if (*(yiziarray+index )) { cout << " * "; } } cout << endl; delete yiziarray; return 0; } int* gene(int num) { //int yinzi[10] ; int* yinzi = new int[10]; int index = 0; int loopnum = num; int i =2; for (; i <= loopnum / 2 ; ) { if (num % i == 0) { yinzi[index] = i; num = num / i ; i = 2; index ++; } else { i++; } } yinzi[index] = '\0'; return yinzi; }