当前位置:网站首页>Judge whether a number is a prime number (prime number)
Judge whether a number is a prime number (prime number)
2022-07-05 17:05:00 【Daily study of bald girls】
Judge whether a number is prime ( Prime number )
prime number : Can only be 1 And the number divided by itself .
use n Divide i( i In turn increase , from 2,3,4… to (n-1) ), If any one exists i You can make n%i=0, explain n Division 1 And other factors outside the body , It's not a prime number . contrary , If the cycle ends without taking a mold 0, Then prime .
Optimize : to n Square root , Header file math.h.
Implementation code :
#include<stdio.h>
#include<math.h>
int sushu(int n) // Judgement primes
{
int i;
for(i=2;i<sqrt(n);i++)
{
if(n%i==0)
return 0; // Not primes
}
return 1; // Prime number
}
int main()
{
int number;
scanf("%d",&number);
sushu(number);
printf("%d\n",sushu(number));
}
Running results :
Prime number , Output 1
Not primes , Output 0
边栏推荐
- 干货!半监督预训练对话模型 SPACE
- sqlserver 做cdc 要对数据库性能有什么要求么
- npm安装
- High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
- How was the middle table destroyed?
- Jarvis OJ Flag
- Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
- The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale
- 【剑指 Offer】66. 构建乘积数组
- 飞桨EasyDL实操范例:工业零件划痕自动识别
猜你喜欢

Games101 notes (II)

American chips are no longer proud, and Chinese chips have successfully won the first place in emerging fields

Learnopongl notes (I)

Jarvis OJ 简单网管协议

Solve cmakelist find_ Package cannot find Qt5, ECM cannot be found

WSL2.0安装

Browser rendering principle and rearrangement and redrawing

Embedded-c Language-1
![[brush title] goose factory shirt problem](/img/c8/44496c767a778101cf3982bd911933.png)
[brush title] goose factory shirt problem

Copy mode DMA
随机推荐
Wsl2.0 installation
Google Earth Engine(GEE)——Kernel核函数简单介绍以及灰度共生矩阵
Writing method of twig array merging
Bs-xx-042 implementation of personnel management system based on SSM
What is ROM
[brush questions] effective Sudoku
Practical example of propeller easydl: automatic scratch recognition of industrial parts
Do sqlserver have any requirements for database performance when doing CDC
Google Earth engine (GEE) -- a brief introduction to kernel kernel functions and gray level co-occurrence matrix
Raspberry pie 4B installation pytorch1.11
Embedded-c Language-5
Can you help me see what the problem is? [ERROR] Could not execute SQL stateme
Learnopongl notes (II) - Lighting
[brush title] goose factory shirt problem
齐宣王典故
Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
Deep dive kotlin synergy (XXI): flow life cycle function
Little knowledge about C language (array and string)
Copy mode DMA
拷贝方式之DMA