博客
关于我
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/

你可能感兴趣的文章
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>
mysqldump的一些用法
查看>>
mysqli
查看>>
MySQLIntegrityConstraintViolationException异常处理
查看>>
mysqlreport分析工具详解
查看>>
MySQLSyntaxErrorException: Unknown error 1146和SQLSyntaxErrorException: Unknown error 1146
查看>>
Mysql_Postgresql中_geometry数据操作_st_astext_GeomFromEWKT函数_在java中转换geometry的16进制数据---PostgreSQL工作笔记007
查看>>
mysql_real_connect 参数注意
查看>>
mysql_secure_installation初始化数据库报Access denied
查看>>
MySQL_西安11月销售昨日未上架的产品_20161212
查看>>
Mysql——深入浅出InnoDB底层原理
查看>>
MySQL“被动”性能优化汇总
查看>>
MySQL、HBase 和 Elasticsearch:特点与区别详解
查看>>
MySQL、Redis高频面试题汇总
查看>>