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
请按任意键继续. . .
相关推荐
Polaris北41 分钟前
第二十七天打卡
开发语言·c++·算法
学无止境_永不停歇2 小时前
十一、C++11列表初始化、右值引用和移动语义
开发语言·c++
mjhcsp2 小时前
C++ 背包DP解析
开发语言·c++
juleskk3 小时前
2.15 复试训练
开发语言·c++·算法
楼田莉子3 小时前
Linux学习:线程的同步与互斥
linux·运维·c++·学习
liulun4 小时前
C++ WinRT中的异步
c++·windows
王老师青少年编程5 小时前
2020年信奥赛C++提高组csp-s初赛真题及答案解析(阅读程序第1题)
c++·题解·真题·初赛·信奥赛·csp-s·提高组
会周易的程序员5 小时前
cNetgate插件架构设计详解 动态库 脚本二开lua, python, javascript
javascript·c++·python·物联网·lua·iot
普通网友5 小时前
C++与Rust交互编程
开发语言·c++·算法