编程(c/c++)判断素数

问题描述:

编程(c/c++)判断素数
输入格式(遇0结束)
比如:
3
6
7
8
0
输出格式:
yes
no
yes
no
1个回答 分类:综合 2014-11-19

问题解答:

我来补答
#include
#include
#include
struct box123
{
int a ;
struct box123 *link ;
} ;
typedef struct box123 box ;
int ifYesNo(int x) ;
int main()
{
int i ;
box *head,*temp1,*temp2 ;
head=(box *)malloc(sizeof(box)) ;
head->link=NULL ;
temp1=head ;
while(1)
{
scanf("%d",&i) ;
if(i==0)
break ;
temp2=(box *)malloc(sizeof(box)) ;
temp1->link=temp2 ;
temp2->link=NULL ;
temp1=temp2 ;
temp1->a=i ;
}
if(head->link==NULL)
{
getch() ;
return 0 ;
}
temp1=head ;
temp2=temp1->link ;
while(temp2!=NULL)
{
ifYesNo(temp2->a) ;
temp2=temp2->link ;
}
getch() ;
return 0 ;
}
int ifYesNo(int x)
{
if(x==1)
{
printf("\nnumber error:cannot input \"1\"") ;
return 1 ;
}
if(x==2)
{
printf("\nyes") ;
return 1 ;
}
if(x%2==0)
{
printf("\nno") ;
return 1 ;
}
for(int i=3;i
 
 
展开全文阅读
剩余:2000