我是个菜鸟,问一个很简单的C语言编程题。

2024-12-21 09:13:42
推荐回答(3个)
回答1:

#include
#include

int prime(int n)
{
int i,k;
k=sqrt((double)n);
for(i=2;i<=k;i++)
{
if(n%i==0)
return 0;
}
return 1;
}

int main()
{
int n;
printf("Input n:");
scanf("%d",&n);
if(prime(n))
{
printf("%d is a prime number!\n",n);
}
else
{
printf("%d is not a prime number!\n",n);
}
return 0;
}

回答2:

LS自己写的,就请楼主给些分吧......
咋感觉和卖身似的,呵呵,开个玩笑.

回答3:

/*本人使用Dev-Cpp 4.9.9.2*/
# include < iostream >
# include " math.h "

using namespace std;

bool Judge ( unsigned long long Data )
{
unsigned long long i;
for ( i = 2 ; i < sqrt ( Data ) ; i++ )
if ( Data % 2 == 0 )
return true ;
return false ;
}
int main ( )
{
unsigned long long Data ;
cin >> Data ;
if ( Judge ( Data ) )
cout << "不是质数" ;
else
cout << "是质数" ;
cin . get ( ) ;
cin . get ( ) ;
return 0 ;
}