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
请按任意键继续. . .
相关推荐
老四啊laosi7 小时前
[C++进阶] 24. 哈希表封装unordered_map && unordered_set
c++·哈希表·封装·unordered_map·unordered_set
妙为8 小时前
银河麒麟V4下编译Qt5.12.12源码
c++·qt·国产化·osg3.6.5·osgearth3.2·银河麒麟v4
史迪仔011211 小时前
[QML] QML IMage图像处理
开发语言·前端·javascript·c++·qt
会编程的土豆12 小时前
【数据结构与算法】再次全面了解LCS底层
开发语言·数据结构·c++·算法
低频电磁之道12 小时前
解决 Windows C++ DLL 导出类不可见的编译错误
c++·windows
君义_noip14 小时前
信息学奥赛一本通 4150:【GESP2509七级】⾦币收集 | 洛谷 P14078 [GESP202509 七级] 金币收集
c++·算法·gesp·信息学奥赛·csp-s
Ricky_Theseus14 小时前
静态链接与动态链接
c++
澈20714 小时前
双指针,数组去重
c++·算法
小辉同志15 小时前
207. 课程表
c++·算法·力扣·图论
feng_you_ying_li15 小时前
C++11,{}的初始化情况与左右值及其引用
开发语言·数据结构·c++