3个回答
展开全部
#include "stdio.h"
int main (void)
{
int a, b, i;
int factor_of ( int a );
printf ("请输入一个整数范围: ");
scanf ("%i%i", &a, &b);
printf ("结果是:\n\n");
for ( i = a; i <= b; ++i ) {
if ( i < 0 ) {
printf ("%i = -", i);
a = -i;
}
else {
printf ("%i = ",i);
a = i;
}
if ( factor_of( a ) == 0 )
if ( a == 1 )
printf ("无素因数,但不是素数\n");
else
printf ("素数\n");
}
}
int factor_of ( int a )
{
int i;
for ( i = 2; i <= a/i; ++i )
if ( a % i == 0 ) {
printf ("%i * ", i);
if ( factor_of ( a/i ) == 0 )
printf ("%i\n", a / i);
break;
}
if ( i > a/i )
return 0;
}
我试了,能用。输入任意范围正解。
汗……这次对了吧?
int main (void)
{
int a, b, i;
int factor_of ( int a );
printf ("请输入一个整数范围: ");
scanf ("%i%i", &a, &b);
printf ("结果是:\n\n");
for ( i = a; i <= b; ++i ) {
if ( i < 0 ) {
printf ("%i = -", i);
a = -i;
}
else {
printf ("%i = ",i);
a = i;
}
if ( factor_of( a ) == 0 )
if ( a == 1 )
printf ("无素因数,但不是素数\n");
else
printf ("素数\n");
}
}
int factor_of ( int a )
{
int i;
for ( i = 2; i <= a/i; ++i )
if ( a % i == 0 ) {
printf ("%i * ", i);
if ( factor_of ( a/i ) == 0 )
printf ("%i\n", a / i);
break;
}
if ( i > a/i )
return 0;
}
我试了,能用。输入任意范围正解。
汗……这次对了吧?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询