Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5844133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:15:01+00:00 2026-05-22T12:15:01+00:00

#include <iostream> #include <limits> #include <cmath> using namespace std; int main() { int number;

  • 0
#include <iostream>
#include <limits>
#include <cmath>

using namespace std;

int main()
{
    int number;
    cout << "Enter the number whose sqare root needs to be calculated";
    cin >> number;
    cout << "Square root of " << number << " is " << (int)sqrt((float)number)  << " OR " << sqrt((float)number) << endl;
    if( (int)sqrt((float)number) == sqrt((float)number) )
    cout << "The number is a perfect sqaure";
    else
    cout << "The number is not a perfect square";
    //To find the nearest perfect square if the number entered
   // is not a perfect square?

    return 0;
}

I hope what i have done to check the perfect squares is OK, but furthermore I want to
find out the number nearest perfect square if the number entered is not a perfect square
Any Ideas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:15:01+00:00Added an answer on May 22, 2026 at 12:15 pm

    Actually, here is the better answer:

    int number = 13;
    int iRoot = static_cast<int>(sqrt(static_cast<float>(number)) + .5f);
    

    You don’t need to check between the ceil or the floor of which is greater, doing a simple round does the trick.

    sqrt(13) is 3.6 and when you add .5 casts to 4. sqrt(12) is 3.46 and when you add .5 casts to 3. (we’re trying to round, that’s why we add the .5). As you can see, when number is closer to the higher root, it’ll give you a decimal greater than .5; when the number is closer to a lower value root, the decimal is less than .5, simple as that!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iostream> using namespace std; int main() { double u = 0; double w
#include <iostream> #include <vector> using namespace std; int main() { vector< vector<int> > dp(50000,
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
#include <iostream> using namespace std; typedef int MYINT; int main() { int y =
I can't understand why this works: #include <iostream> using namespace std; int main(){ signed
#include<iostream> using namespace std; class A { int a; int b; public: void eat()
#include <iostream> using namespace std; class Base { public: Base(){cout <<Base<<endl;} virtual ~Base(){cout<<~Base<<endl;} virtual
#include <iostream> #include <queue> using namespace std; struct Call { Call( int callNum, long
#include <iostream> #include <string> #include <regex> #include <ios> #include <locale> using namespace std; int
#include <iostream> using namespace std; template<typename T> void test() { cout << 1; }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.