判斷一個數的平方根是否為整數(一個數開方是否是整數,支持大數)


判斷一個數的平方根是否為整數

//原理我也不是很清楚。。。
if(sqrt(num)==(ll)sqrt(num)){
    cout<<"sqrt(num)是整數";
}else{
    cout<<"sqrt(num)不是整數";
}

//示例程序

#include <bits/stdc++.h> 
 
using namespace std;
 
typedef long long ll;

int main(){
	if(sqrt(4)==(int)sqrt(4)){
		cout<<"int";
	}else cout<<"no int";
	cout<<endl;
	if(sqrt(5)==(int)sqrt(5)){
		cout<<"int";
	}else cout<<"no int";
	return 0;
}

image-20201113220536452


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM