当前位置:网站首页>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
边栏推荐
- Iphone14 with pill screen may trigger a rush for Chinese consumers
- Apple has abandoned navigationview and used navigationstack and navigationsplitview to implement swiftui navigation
- NPM installation
- [Jianzhi offer] 61 Shunzi in playing cards
- Bs-xx-042 implementation of personnel management system based on SSM
- 【729. 我的日程安排錶 I】
- How to uninstall MySQL cleanly
- 美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
- PHP strict mode
- Embedded-c Language-4
猜你喜欢
Iphone14 with pill screen may trigger a rush for Chinese consumers
Embedded UC (UNIX System Advanced Programming) -1
[61dctf]fm
Jarvis OJ Flag
Games101 notes (III)
Basic introduction to the control of the row component displaying its children in the horizontal array (tutorial includes source code)
[brush questions] effective Sudoku
Learnopongl notes (I)
Flet tutorial 12 stack overlapping to build a basic introduction to graphic and text mixing (tutorial includes source code)
Bs-xx-042 implementation of personnel management system based on SSM
随机推荐
[Jianzhi offer] 61 Shunzi in playing cards
How does the outer disk futures platform distinguish formal security?
American chips are no longer proud, and Chinese chips have successfully won the first place in emerging fields
叩富网开期货账户安全可靠吗?怎么分辨平台是否安全?
项目引入jar从私服Nexus 拉去遇到的一个问题
手机开证券账户安全吗?怎么买股票详细步骤
Wsl2.0 installation
【Web攻防】WAF检测技术图谱
[team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details
【刷題篇】鹅廠文化衫問題
Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
Summary of PHP pseudo protocol of cisp-pte
Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
It is forbidden to copy content JS code on the website page
美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
Combined use of vant popup+ other components and pit avoidance Guide
Facing new challenges and becoming a better self -- attacking technology er
网站页面禁止复制内容 JS代码
Fleet tutorial 09 basic introduction to navigationrail (tutorial includes source code)
Machine learning compilation lesson 2: tensor program abstraction