Posted on 2007-04-10 15:20
UniK 阅读(721)
评论(0) 编辑 收藏 引用 所属分类:
IT技术
#include <iostream.h>
unsigned long a[100];
unsigned long n;
void find(unsigned long nowf, unsigned long nowmul, unsigned long lastf) {
if (nowmul == 1) {
//output
unsigned long product = 1;
for (long i = 0; product != n; i++) {
if (i == 0) cout << n << "=" << a[i];
else cout << "*" << a[i];
product = product * a[i];
}
cout << endl;
}
for (long i = 2; i <= lastf; i++) {
if ((nowmul / i > 0) && (nowmul % i == 0)) {
a[nowf] = i;
find(nowf + 1, nowmul / i, i);
}
}
}
void main() {
for (long i = 0; i < 10; i++) {
a[i] = 0;
}
cout << "input a integer(>0):";
cin >> n;
find(0, n, n);
}