编程(c/c++)判断素数
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/10/06 11:50:34
编程(c/c++)判断素数
输入格式(遇0结束)
比如:
3
6
7
8
0
输出格式:
yes
no
yes
no
输入格式(遇0结束)
比如:
3
6
7
8
0
输出格式:
yes
no
yes
no
#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
#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
C语言编程题,判断素数.
判断是否为素数,C语言编程
C语言编程:输入一个数判断是否为素数(质数),输出判断结果信息(prime number素数).
c语言编程题!有关素数的!
c语言编程:输入一个正整数n,判断它是否为素数
C语言怎么判断素数?
C语言编程:判断是否是素数,如果不是,则由小到大打印其所有的整数因子
用c语言写:输入一个整数,利用函数调用方式编程,判断该数是否为素数.(素数的条件:只能被1和自身整除
素数统计编程c语言给定一段连续的正整数,请判断其中素数的个数;输入描述输入数据包含2个正整数A和B(0
c语言编程 找出所有的100-999回文素数
c语言编程:找出自然数中第20个素数
写一个C语言编程,求素数及反序数