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
请按任意键继续. . .
相关推荐
L_09078 小时前
【C++】异常
开发语言·c++
liulilittle8 小时前
关于拥塞控制的几点思考
网络·c++·tcp/ip·计算机网络·信息与通信·tcp·通信
QT-Neal10 小时前
C++ 编码规范
c++
啦啦啦啦啦zzzz10 小时前
数据结构:红黑树理论
数据结构·c++·红黑树
Yolo_TvT11 小时前
C++:默认构造函数
c++
小欣加油12 小时前
leetcode994 腐烂的橘子
数据结构·c++·算法·leetcode·bfs
.千余13 小时前
【C++】手写双向链表:list容器模拟实现
开发语言·c++·笔记·学习·其他
liulilittle13 小时前
过冲:拥塞控制的呼吸与盲行
linux·网络·c++·tcp/ip·计算机网络·tcp·通信
小欣加油14 小时前
leetcode2574 左右元素和的差值
数据结构·c++·算法·leetcode·职场和发展
weixin_4617694014 小时前
通过数组和队列构造二叉树方法(用于算法测试),C++ vector不能直接使用null
数据结构·c++·算法·vector·nullptr·null