当前位置:网站首页>[C language series] - print prime numbers between 100 and 200
[C language series] - print prime numbers between 100 and 200
2022-07-29 05:34:00 【Gancheng なつき】
꧁ Hello, everybody ! It is a great honor to have your visit , Let's have a long way to go in programming !꧂
* Blog column :【C All living things 】*
Introduction to this article :C Language implementation 100~200 Print prime numbers between !
Get to know the author : Aspire to be a great programmer , Xiaobai, who is currently a sophomore in College .
Inspirational terms : The tediousness of programming , Let's study together and become interesting !
Text begins
List of articles
What is a prime number
For prime numbers, a number can be 1 And divide themselves , Besides, it cannot be divided by any number
such as : take 13 For this number , Besides being 1 And myself 13 In addition to Division , It can't be divided by any number
Common prime numbers, such as :1,2,3,5,7,11,13,17…
Their thinking
The method we use here is : Trial division ( Use more than 2 To a number less than or equal to this number to modulus with this number , If the remainder is 0 It's not a prime , If it is not 0, Just print this number ( As a prime number ))
3. Directly start a code to see :
#define _CRT_SECURE_NO_WARNINGS 1
// Print 100~200 The prime between
#include<stdio.h>
int main()
{
int i = 0;// So let's define one i, Prepare for the next cycle
for (i = 100; i <= 200; i++)// Define a for loop
{
int j = 0;// Define a for use with 100-200 Divide the numbers between
for (j = 2; j <= i; j++)// Use more than 2, Less than i Of j modulus
{
if (i % j == 0)// if i Can be j Divide and jump out of the loop
{
break;
}
}
if (j>=i)//j Keep looking for , Until greater than is found i The number of is not found to be divisible , Is a prime number
{
printf("%d ", i);// Print out prime numbers
}
}
return 0;
}Finally, the result of running is :

4. We all know that even numbers cannot be prime numbers, so we can further modify our code : It was originally i++ Of , It can be changed to i+2 :
#include<stdio.h>
int main()
{
int i = 0;// So let's define one i, Prepare for the next cycle
for (i = 101; i <= 200; i+=2)// Define a for loop
{
int j = 0;// Define a for use with 100-200 Divide the numbers between
for (j = 2; j <= i; j++)// Use more than 2, Less than i Of j modulus
{
if (i % j == 0)// if i Can be j Divide and jump out of the loop
{
break;
}
}
if (j>=i)//j Keep looking for , Until greater than is found i The number of is not found to be divisible , Is a prime number
{
printf("%d ", i);// Print out prime numbers
}
}
return 0;
}The final result is the same as before !
( Just a novice blogger , No, you can help point out , modify )
边栏推荐
- Pyqt5: Chapter 1, Section 1: creating a user interface using QT components - Introduction
- B - identify floating point constant problems
- 【C语言系列】—文件操作详解(上)
- Best practices for elastic computing in the game industry
- 冒泡排序 C语言
- 哈夫曼树以及哈夫曼编码在文件压缩上的应用
- MySQL的基础概念+数据库系统结构+拓展延申+基础命令学习
- Day 2
- ClickHouse学习(九)clickhouse整合mysql
- Clickhouse learning (XI) clickhouseapi operation
猜你喜欢

第三课threejs全景预览房间案例

shell基本操作(下)

游戏行业弹性计算最佳实践

MySQL的基础概念+数据库系统结构+拓展延申+基础命令学习

【C语言系列】— 一道递归小题目

哈夫曼树以及哈夫曼编码在文件压缩上的应用

Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)

【C语言系列】—深度解剖数据在内存中的存储(一) 暑假开篇

Day 1

公众号不支持markdown格式文件编写怎么办?
随机推荐
C language one-dimensional array
Li Kou 994: rotten orange (BFS)
paddle.fluild常量计算报错‘NoneType‘ object has no attribute ‘get_fetch_list‘
ClickHouse学习(四)SQL操作
EXIT中断详解
整数溢出和打印
【C语言系列】— 字符串+部分转义字符详解+注释小技巧
副作用和序列点
终端shell常用命令
Differences between texture2d and texture2dproj under webgl1.0
Clickhouse learning (IX) Clickhouse integrating MySQL
抢先预约 | 阿里云无影云应用线上发布会预约开启
用threejs 技术做游戏跑酷
Live broadcast preview | how to save 30% labor cost and shorten 80% trademark processing cycle?
C语言 一维数组
Day 1
MySQL的基础概念+数据库系统结构+拓展延申+基础命令学习
Abstract classes and interfaces
Longest string without duplicate characters
Day 2