C 练习实例12

**题目:**判断 101 到 200 之间的素数

代码示例

cpp 复制代码
#include <stdio.h>
#include <math.h>
bool IsPrime (int m)
{
	for(int i=2;i<=(int)sqrt((double)m);i++) {
		if(m%i==0){
			return false;
		}
	}
	return true;
}
int main()
{
	int cnt=0;
	for(int m=101;m<=200;m++) {
		if(IsPrime(m)) {
			printf("%d",m);
			cnt++;
			if(cnt%5)
				printf(" ");
			else
				printf("\n");
		}
	}
	return 0;	
}

输出

cpp 复制代码
101 103 107 109 113
127 131 137 139 149
151 157 163 167 173
179 181 191 193 197
199
--------------------------------
Process exited after 0.2834 seconds with return value 0
请按任意键继续. . .
相关推荐
端平入洛21 小时前
auto有时不auto
c++
哇哈哈20212 天前
信号量和信号
linux·c++
多恩Stone2 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马2 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
超级大福宝2 天前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode
weiabc2 天前
printf(“%lf“, ys) 和 cout << ys 输出的浮点数格式存在细微差异
数据结构·c++·算法
问好眼2 天前
《算法竞赛进阶指南》0x01 位运算-3.64位整数乘法
c++·算法·位运算·信息学奥赛
yyjtx2 天前
DHU上机打卡D31
开发语言·c++·算法
czxyvX2 天前
020-C++之unordered容器
数据结构·c++
会编程的土豆2 天前
2.25 做题
数据结构·c++·算法