c语言 求质因子题目改错,程序能运行,但是得不到正确的答案,求解!
#include"stdio.h"intIsPrime(intn){inti,m;m=1;for(i=2;i<n;i++){if(n%i){m=0;break;}}ret...
#include "stdio.h"
int IsPrime(int n)
{
int i, m;
m = 1;
for (i = 2; i < n; i++) {
if (n%i) {
m = 0;
break;
}
}
return m;
}
main()
{
int j, k;
system("cls");
printf("\nPlease enter an integer number between 2 and 10000: ");
scanf("%d", &k);
printf("\n\nThe prime factor(s) of %d is( are ):", k);
for (j = 2; j <= k; j++) {
if ((!(k%j)) && (IsPrime(j))) {
printf("\n %4d", j);
printf("\n");
}
}
getch();
} 展开
int IsPrime(int n)
{
int i, m;
m = 1;
for (i = 2; i < n; i++) {
if (n%i) {
m = 0;
break;
}
}
return m;
}
main()
{
int j, k;
system("cls");
printf("\nPlease enter an integer number between 2 and 10000: ");
scanf("%d", &k);
printf("\n\nThe prime factor(s) of %d is( are ):", k);
for (j = 2; j <= k; j++) {
if ((!(k%j)) && (IsPrime(j))) {
printf("\n %4d", j);
printf("\n");
}
}
getch();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询