当前位置:网站首页>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
边栏推荐
- [Web attack and Defense] WAF detection technology map
- Little knowledge about C language (array and string)
- Use byte stream to read Chinese from file to console display
- 网站页面禁止复制内容 JS代码
- Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
- Benji Banas membership pass holders' second quarter reward activities update list
- Yarn common commands
- It is forbidden to copy content JS code on the website page
- Application of threshold homomorphic encryption in privacy Computing: Interpretation
- Is it safe to open futures accounts online? Will there be more liars online? Doesn't feel very reliable?
猜你喜欢
Benji Banas membership pass holders' second quarter reward activities update list
浏览器渲染原理以及重排与重绘
How to uninstall MySQL cleanly
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
【性能测试】jmeter+Grafana+influxdb部署实战
Jarvis OJ Flag
Jarvis OJ Webshell分析
干货!半监督预训练对话模型 SPACE
Deep learning plus
Learnopongl notes (I)
随机推荐
Raspberry pie 4B installation pytorch1.11
Embedded-c Language-2
国内首家 EMQ 加入亚马逊云科技「初创加速-全球合作伙伴网络计划」
美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
编译libssh2报错找不到openssl
手机开证券账户安全吗?怎么买股票详细步骤
阈值同态加密在隐私计算中的应用:解读
Application of threshold homomorphic encryption in privacy Computing: Interpretation
C how TCP restricts the access traffic of a single client
Is it safe to open an account for digging wealth stocks? How is it safe to open a stock account?
Use byte stream to read Chinese from file to console display
【刷題篇】鹅廠文化衫問題
Learnopongl notes (I)
Is it safe for qiniu business school to open a stock account? Is it reliable?
npm安装
Jarvis OJ webshell analysis
Little knowledge about C language (array and string)
Error in composer installation: no composer lock file present.
Allusions of King Xuan of Qi Dynasty