博客
关于我
Problem B: 判断素数的函数
阅读量:258 次
发布时间:2019-03-01

本文共 863 字,大约阅读时间需要 2 分钟。

Problem B: 判断素数的函数

Description

编写一个判断素数的函数,主函数中利用这个函数,打印出n与m之间的所有素数。

Input

多组测试数据,每组输入2个整数n和m,其中1 < n <= m <= 1000

Output

在一行输出n和m之间(包含n和m)的所有素数,中间用空格隔开,最后一个数后面没有空格。

Sample Input

2 14

Sample Output

2 3 5 7 11 13

#include 
int isPrime(unsigned int n)//定义素数函数{ int i; if(n == 0 || n == 1) return 0; for(i = 2; i * i <= n; i++) { if(n % i == 0) return 0; } return 1;}int main(void)//主函数{ int i,count=0,m,n,t=1; while(scanf("%d%d",&m,&n)!=EOF){ for(i = m; i <= n; i++) { if(t==1){ if(isPrime(i)) { printf("%d",i); t=0;continue; } } if(t==0){ if(isPrime(i)) { printf(" %d",i); } } } printf("\n"); } return 0;}

转载地址:http://zsux.baihongyu.com/

你可能感兴趣的文章
MySQL 字符串截取函数,字段截取,字符串截取
查看>>
MySQL 存储引擎
查看>>
mysql 存储过程 注入_mysql 视图 事务 存储过程 SQL注入
查看>>
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>
mysql 导入 sql 文件时 ERROR 1046 (3D000) no database selected 错误的解决
查看>>
mysql 导入导出大文件
查看>>
MySQL 导出数据
查看>>
mysql 将null转代为0
查看>>
mysql 常用
查看>>
MySQL 常用列类型
查看>>
mysql 常用命令
查看>>
Mysql 常见ALTER TABLE操作
查看>>