【发布时间】:2013-08-02 18:32:05
【问题描述】:
我正在编写一个程序来查找给定数字的素阶乘。
虽然程序运行良好,但我有两个问题。
1. 当我输入一个奇数时,它会在结果中打印 2,虽然 2 不应该在其中。
2. 15秒后变成无限循环,真是毛骨悚然。
#include<stdio.h>
#include<conio.h>
int num(int); // Making a function for finding prime factors
int main()
{
int i,j;
printf("Enter any number");
scanf("%d",&i);
num(i);
getch();
}
int num(int i)
{
int a=2;
while(a<=i)
{
if(i%a==0) //if the number is divisible then divide it
i=i/a;
printf(" %d",a);
if(i%a!=0)
{
i%a;
while(i%a!=0)// If it is not divisible by 2 then increment it until it is
a++;
}
}
}
【问题讨论】:
-
输出后出现无穷大
-
说我输入56,然后它会告诉我因素,然后过一段时间,它变成一个无限循环
-
它只是重复打印-1
-
这条声明,
i%a;它什么都没有。