当前位置:网站首页>[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 )
边栏推荐
猜你喜欢

Clickhouse learning (IX) Clickhouse integrating MySQL

【C语言系列】—深度解剖数据在内存中的存储(二)-浮点型

Global components component registration

ClickHouse学习(八)物化视图

B - identify floating point constant problems

365 day challenge leetcode 1000 questions - day 037 elements and the maximum side length of squares less than or equal to the threshold + the number of subsequences that meet the conditions

【剑指offer】— 详解库函数atoi以及模拟实现atoi函数

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

Occt learning 001 - Introduction

Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)
随机推荐
微信小程序视频上传组件直接上传至阿里云OSS
On Paradigm
C language one-dimensional array
Clickhouse learning (IV) SQL operation
牛客网编程题—【WY22 Fibonacci数列】和【替换空格】详解
递归的基本原理
【C语言系列】— 一道递归小题目
【C语言系列】—深度解剖数据在内存中的存储(一) 暑假开篇
Talking about Servlet
Playwright实战案例之爬取js加密数据
小程序中的DOM对象元素块动态排序
三次握手四次挥手针对面试总结
Alibaba cloud and Dingjie software released the cloud digital factory solution to realize the localized deployment of cloud MES system
C language file operation
Camunda 1、Camunda工作流-介绍
Three handshakes and four waves for the interview summary
Time complexity and space complexity
浅谈范式
paddle. Fluid constant calculation error 'nonetype' object has no attribute 'get_ fetch_ list‘
365 day challenge leetcode 1000 questions - day 042 array sequence number conversion + relative ranking discretization processing