Answer to Question #313480 in C++ for dhrubo

Question #313480

Write and run a C++ program to test the following is_square() function that determines whether the given integer is a square number


1
Expert's answer
2022-03-17T15:18:26-0400

Here is program:

void is_square(unsigned number)
{
    unsigned sqr = 0;
    for (unsigned i = 1; sqr + 2 <= number; i += 2)
        sqr += i;


    cout << (number == sqr || number == 1 ? "Yes" : "No") << std::endl;
}
int main()
{
	int num;
    cout << "Enter number: ";
    cin >> num;
	is_square(num);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog