当前位置:网站首页>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
边栏推荐
- C# TCP如何限制单个客户端的访问流量
- If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats
- 手机开证券账户安全吗?怎么买股票详细步骤
- The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
- Embedded-c Language-1
- Android privacy sandbox developer preview 3: privacy, security and personalized experience
- 精准防疫有“利器”| 芯讯通助力数字哨兵护航复市
- Jarvis OJ Telnet Protocol
- [first lecture on robot coordinate system]
- Jarvis OJ webshell analysis
猜你喜欢

Application of threshold homomorphic encryption in privacy Computing: Interpretation

Benji Banas membership pass holders' second quarter reward activities update list

Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.
![[729. My schedule I]](/img/e3/32914227d00cf7595ee850e60f2b72.png)
[729. My schedule I]

【729. 我的日程安排表 I】

Jarvis OJ 远程登录协议

Basic introduction to the control of the row component displaying its children in the horizontal array (tutorial includes source code)

Practical example of propeller easydl: automatic scratch recognition of industrial parts

NPM installation

Jarvis OJ 简单网管协议
随机推荐
【机器人坐标系第一讲】
Detailed explanation of use scenarios and functions of polar coordinate sector diagram
Etcd 构建高可用Etcd集群
Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
Games101 notes (I)
How can C TCP set heartbeat packets to be elegant?
浏览器渲染原理以及重排与重绘
Deeply cultivate 5g, and smart core continues to promote 5g applications
Practical example of propeller easydl: automatic scratch recognition of industrial parts
ECU简介
深潜Kotlin协程(二十一):Flow 生命周期函数
Jarvis OJ 简单网管协议
【剑指 Offer】62. 圆圈中最后剩下的数字
[brush questions] effective Sudoku
外盘期货平台如何辨别正规安全?
[61dctf]fm
npm安装
Raspberry pie 4B installation pytorch1.11
Embedded -arm (bare board development) -1
Writing method of twig array merging