质因数(for c)

写一个函数输出一个数的质因数int PrimeFactor(const int a)

int PrimeFactor(const int a)
{
	int k = a;
	
	if (a <= 2) {
		return -1;
	}
	
	for (int i = 2; i <= k; ++i) {
		if ((k % i) == 0) {
			printf("%d\t", i);
			k = k / i;
			i--;
		}
	}
	
	return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/sciapex/p/12360046.html
今日推荐