###### 编程介的小学生

2017-08-26 04:40 阅读 1.1k

# 素数判定

Problem Description

Input

Output

Sample Input
0 1
0 0

Sample Output
OK

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享

#### 2条回答默认 最新

• 已采纳
晗生缘 2017-08-26 05:55

C语言版本
Anywise, If you have any issue, please let me know. Thanks.

#include "stdio.h"
#include "math.h"
#include "string.h"

int Decision_Prime(int num)//**There is deciding whether the num is prime. The Number "0" was representative prime and "1" was no prime.**
{
int i = 2;

``````    while(i < num)
{
if(num % i == 0)
{
break;
}
i++;
}
if(num == i)
{
return 0;
}
else
{
return1;
}
``````

}

int main()
{
int x,y,n;
int flag = 0;

``````//**input the number (x,y)**
printf("Please input the X-value:");
scanf("%d",&x);
printf("Please input the Y-value:");
scanf("%d",&y);

n = x+1;

while(n < y)
{
flag = Decision_Prime(n);
if(flag != 0)
{
break;
}
n++;
}
if(n==y)
{
printf("OK\n");
}
else
{
printf("Sorry\n");
}
return 0;
``````

}

点赞 评论 复制链接分享
• 东风玖哥 2017-08-26 08:24

建议你看看《算法之美》，用双层递归

点赞 评论 复制链接分享