当前位置:网站首页>判断素数
判断素数
2022-07-17 05:09:00 【倫之】
public static void main(String args[]){
3 //1既不是质数也不是和数,使用i从2开始。
4 for(int i=2;i<=1000;i++){
5 boolean flag = true;
6 for(int j = 2;j < i;j++){
7 if(i % j==0){
8 flag = false;
9 break;//到了1000内的质数,就跳出循环,并输出结果。
10 }
11 }
12 if(flag){
13 System.out.print(" "+i);
14 }
15 }
16 }C++
#include <stdio.h>
int main(){
int a=0; // 素数的个数
int num=0; // 输入的整数
printf("输入一个整数:");
scanf("%d",&num);
for(int i=2;i<num;i++){
if(num%i==0){
a++; // 素数个数加1
}
}
if(a==0){
printf("%d是素数。\n", num);
}else{
printf("%d不是素数。\n", num);
}
return 0;
}
边栏推荐
- Rk356x u-boot Institute (command section) 3.4 usage of MEM memory related commands
- Use of log4j
- redis 源码分析 动态字符串实现(sds)
- 基于libco的协程实现6 libcurl的同步接口的实现方案
- 基于PaddleOCR解决文本检测训练模型与inference模型预测效果不一致的问题
- 性能瓶颈查找-火焰图分析
- Rxjs source code analysis (I) observable
- 分布式注册中心-etcd
- What is the employment prospect of software testing? There is a large demand for talents and strong job stability
- Talk about 20 negative teaching materials for writing code
猜你喜欢

Cesium geojson数据的添加与移除

Network command: network card information, netstat, ARP

UML (use case diagram, class diagram, object diagram, package diagram)

ArcGIS point cloud (XYZ) data to DEM

mysql 缓存策略和解决方案

用Flink SQL流化市场数据2:盘中风险价值

Web3js development technology

面试官:大量请求 Redis 不存在的数据,从而影响数据库,该如何解决?

一次全面的性能优化,从5秒优化到1秒

BUUCTF web WarmUp
随机推荐
BUUCTF 杂项——二维码
Easypoi excel multi sheet import
ArcMap creates a constant grid and tessellates it into a new grid
线上软件测试培训机构柠檬班与iTest.AI平台达成战略合作
ArcGIS 点云(xyz)数据转DEM
Redis source code analysis - data structure and Implementation (Dictionary dict)
Buuctf miscellaneous - QR code
Cesium 綁定鼠標事件和移除鼠標事件
MySQL cache solution problem solving
2020-10-22
Redis 源码分析-数据结构及实现(字典dict)
Easypoi之excel多sheet导入
redis 源码分析 动态字符串实现(sds)
循环赛制日程表问题
Distributed registry etcd
C语言的高级操作
H5 page uses JS to generate QR code
Excel导入长数据末尾变000
路由器loopback口实验
Rxjs源码解析(一)Observable