当前位置:网站首页>Explanation and usage of sqrt() function
Explanation and usage of sqrt() function
2022-06-28 21:12:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
sqrt() Function is a function we often use . Now I will introduce its usage and usage specification in detail
Required header file
#include<math.h>The function prototype
double sqrt(double x);effect : sqrt() Used to find the square root of a given value
Common usage errors Output 36 The root of the root
Ignored sqrt() The return value of the function is double type . Make a mistake
The solution is as follows :
Common use sqrt() The standard writing of functions for example : We have to judge whether a number is a prime number , Just judge 2 ~ n Square root If there is a number that can be divided by an integer The wrong way to write :
bool find(int n)
{
for(int i=2;i<=sqrt(n);i++)
{
if(n%i==0)
return false;
}
return true;
}The way it's written is , Actually, it is not recommended to write in this way . Although I often write like this . But in the process of doing questions , Just because of this writing program appeared bug. I'll use the following safe way of writing Correct writing :
bool find(int n)
{
int sql=(int)sqrt(1.0*n);//1.0*n Is the purpose of Implicit conversion to floating point number , Cast to integer after root
for(int i=2;i<=sql;i++)
{
if(n%i==0)
return false;
}
return true;
}Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/132640.html Link to the original text :https://javaforall.cn
边栏推荐
- Leetcode daily question - Sword finger offer II 091 Paint the house
- [learning notes] cluster analysis
- CNN-LSTM的flatten
- 接口用例设计
- Learning Tai Chi Maker - mqtt Chapter II (VII) esp8266 mqtt Testament application
- The comprehensive application of the setstack computer (uva12096) Purple Book p116stl
- LeetCode877. Stone game
- Bitbucket failed to pull the warehouse Using SSH
- 职场小技巧 | 了解岗位优势三板斧之“识人”
- 开通挖财账号安全吗?是靠谱的吗?
猜你喜欢

【笔记:模拟MOS集成电路】带隙基准(基本原理+电流模+电压模电路详解)

LeetCode每日一题——515. 在每个树行中找最大值

Interface test process

【Try to Hack】Cobalt Strike(一)

How to analyze the relationship between enterprise digital transformation and data asset management?

Bitbucket 使用 SSH 拉取仓库失败的问题

Learning Tai Chi Maker - mqtt Chapter II (VII) esp8266 mqtt Testament application

Data standardization processing

什么是接口?什么是接口测试?

Ehcache configuration data, convenient for self checking
随机推荐
嵌入式中 动态阿拉伯语字符串 转换 LCD显示字符串【感谢建国雄心】
接口用例设计
2. integrate filter
LeetCode每日一题——324. 摆动排序 II
Binary tree problems
APISIX 助力中东社交软件,实现本地化部署
Apisik helps Middle East social software realize localized deployment
在哪个软件上开户比较安全,开户流程是什么?
Figure neural network can also be used as CV backbone model. Huawei Noah Vig architecture is comparable to CNN and transformer
Application practice | 1billion data second level correlation. Huolala's OLAP System Evolution Based on Apache Doris (with PPT download)
Which software is safer to open an account on and what is the account opening process?
LeetCode122. 买卖股票的最佳时机II
职场小技巧 | 了解岗位优势三板斧之“识人”
图神经网络也能用作CV骨干模型,华为诺亚ViG架构媲美CNN、Transformer
Leetcode: merge two ordered linked lists_ twenty-one
请问同业存单是否靠谱,安全吗
Application of the purple book p113map of ananagrams (uva156)
LeetCode1114. Print in sequence
Is the rapid SSL wildcard certificate genuine in 1981
炒股票能赚钱么?开户安全嘛