写一个判断素数的函数,在主函数输入一个整数,输出是否是素数的消息。

#include<stdio.h>
int test(int x){
int i=1;
for(i=1;i<x;i++){
if(x%i==0&&x>2)
return 0;
else
return 1;




}


}
int main(){
int test(int x);
int b;
printf("输入整数:\n");
scanf("%d",&b);
if(test(b)==0)
printf("非素数");
else
printf("素数");
return 0;


}

   

猜你喜欢

转载自www.cnblogs.com/xujiucheng/p/9247948.html