我想编写一个程序,用计数器而不是scanf
查找数字的素因式分解。我已经实现了一些代码,但没有得到想要的结果!
#include<stdio.h>
#define MAX 1000
int main()
{
int num;
int counter;
int factor = 2;
for (counter = 2; counter <= MAX; counter++) {
printf("factorazation of number %d is",counter);
while (factor<counter) {
int power = 0;
if (counter%factor == 0) {
// int power=0;
while (counter%factor == 0) {
counter = counter / factor;
power++;
}
printf("%d^%d\n",factor,power);
if (counter != 1)
printf("X");
}
factor++;
}
if (counter != 1)
printf("%d^1.\n",factor);
// printf("factorazation of number %d is",counter);
}
}