永发信息网

求助编程大神???

答案:3  悬赏:40  手机版
解决时间 2021-03-26 08:23
  • 提问者网友:一抹荒凉废墟
  • 2021-03-25 15:31
求助编程大神???
最佳答案
  • 五星知识达人网友:想偏头吻你
  • 2021-03-25 16:29
#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<(x+1)/2;i++)
{
if(x%i==0)
{
printf("\nno") ;
return 1 ;
}
}
printf("\nyes") ;
return 1 ;
}

//编译环境 VS2005,估计其他编译器也能编译。
//完全按你的要求做的,你看看我提交答案的时间几点了。。。不给个采纳我和你拼命。。。
全部回答
  • 1楼网友:往事埋风中
  • 2021-03-25 18:44
“可以用这个数去除以从2开始到它一半大的数...如果没有余数为0就输出No...如果有一个余数为0就跳出循环输出Yes... ”
其实从2到对它开根号的数即可,不用到它的一半,见教程。
  • 2楼网友:北城痞子
  • 2021-03-25 17:42
可以用这个数去除以从2开始到它一半大的数...如果没有余数为0就输出No...如果有一个余数为0就跳出循环输出Yes...追问可不可以完整的代码让我看看,拜谢!!追答这个是输入一个数的- -没调试过...如果有问题的话应该是if(count==(input/2-1)){有问题...
int main(){
int input=0;
cin>>input;
int count=0;
for(int i=2;i<=input/2+1;i++){
if(input%i==0)
{
cout<<"No"<break;
}
count++;
if(count==(input/2-1)){
cout<<"Yes"<}
}
system("pasue");
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯