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
请按任意键继续. . .
相关推荐
南郁5 小时前
007-nlohmann/json 项目应用-C++开源库108杰
c++·开源·json·nlohmann·现代c++·d2school·108杰
菠萝017 小时前
共识算法Raft系列(1)——什么是Raft?
c++·后端·算法·区块链·共识算法
海棠蚀omo7 小时前
C++笔记-C++11(一)
开发语言·c++·笔记
凌佚8 小时前
rknn优化教程(一)
c++·目标检测·性能优化
Lenyiin10 小时前
《 C++ 点滴漫谈: 四十 》文本的艺术:C++ 正则表达式的高效应用之道
c++·正则表达式·lenyiin
yxc_inspire12 小时前
基于Qt的app开发第十三天
c++·qt·app·tcp·面向对象
虾球xz12 小时前
CppCon 2015 学习:Concurrency TS Editor’s Report
开发语言·c++·学习
潇-xiao12 小时前
Qt 按钮类控件(Push Button 与 Radio Button)(1)
c++·qt
板鸭〈小号〉12 小时前
命名管道实现本地通信
开发语言·c++
YKPG14 小时前
C++学习-入门到精通【14】标准库算法
c++·学习·算法