Square Root (Integral) c++
Given a number N, find its square root. You need to find and print only the integral part of square root of N.
For eg. if number given is 18, answer is 4.
Answers
Answered by
2
1. Accept the number.
2. Use sqrt() by including <cmath> header file.
3. Use type casting to convert double to int.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
cout<<"Enter a number: ";
cin>>n;
cout<<"Integral part of sqrt: "<<(int)(sqrt(n));
return 0;
}
Enter a number: 18
Integral part of sqrt: 4
See attachment for verification.
Attachments:
Similar questions