#include "stdio.h"
void Prime(int);
int main(void){
unsigned int n;
scanf("%u",&n);
Prime(n);
return 0;
}
void Prime(int n){
int i,k=0;
if(n!=2&&n%2==0)
printf("the number is not prime.");
else{
do{
i=3;
if(n==i||n%i!=0)
k=1;
i+=2;
}while(i*i<=n);
if(k==1)
printf("the number is prime.");
else
printf("the number is not prime.");
}
return ;
}
#include "stdio.h"
void Prime(int);
int main(void){
unsigned int n;
scanf("%u",&n);
Prime(n);
return 0;
}
void Prime(int n){
int i,k=0;
if(n!=2&&n%2==0)
printf("the number is not prime.");
else{
do{
i=3;
if(n==i||n%i!=0){
k=1;
i+=2;
}
else{
k=0;
break; //刚才漏掉了
}
}while(i*i<=n);
if(k==1)
printf("the number is prime.");
else
printf("the number is not prime.");
}
return ;
}
我想请您试一下,有没有得到正确答案?