当前位置:网站首页>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
边栏推荐
- composer安装报错:No composer.lock file present.
- WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响
- Application of threshold homomorphic encryption in privacy Computing: Interpretation
- Copy mode DMA
- Embedded UC (UNIX System Advanced Programming) -3
- Embedded-c Language-2
- C# TCP如何限制单个客户端的访问流量
- Sentinel-流量防卫兵
- How does the outer disk futures platform distinguish formal security?
- Wsl2.0 installation
猜你喜欢
【性能测试】jmeter+Grafana+influxdb部署实战
thinkphp模板的使用
WSL2.0安装
深耕5G,芯讯通持续推动5G应用百花齐放
[729. My Schedule i]
PHP人才招聘系统开发 源代码 招聘网站源码二次开发
The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale
The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%
Jarvis OJ shell traffic analysis
精准防疫有“利器”| 芯讯通助力数字哨兵护航复市
随机推荐
What is ROM
Is it safe for qiniu business school to open a stock account? Is it reliable?
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
Practical example of propeller easydl: automatic scratch recognition of industrial parts
Use byte stream to read Chinese from file to console display
Jarvis OJ simple network management protocol
Is it safe to open futures accounts online? Will there be more liars online? Doesn't feel very reliable?
Allusions of King Xuan of Qi Dynasty
Jarvis OJ Flag
Do sqlserver have any requirements for database performance when doing CDC
Raspberry pie 4B installation pytorch1.11
Copy mode DMA
File operation --i/o
Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
sqlserver 做cdc 要对数据库性能有什么要求么
Summary of PHP pseudo protocol of cisp-pte
浏览器渲染原理以及重排与重绘
Learnopongl notes (II) - Lighting
[first lecture on robot coordinate system]
ECU introduction