Find if the number is perfect square without using sqrt function

A number n is a perfect square if any number less than n multplied by itself gives the number n.

Program:

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        if(i*i==n)
        {
            cout<<"Perfect square";
            break;
        }
    }

    return 0;
}




output:

25
Perfect square


625
Perfect square

Comments

Popular posts from this blog

C program to print the following Pattern

For any given matrix find the path from the start to the end which gives the maximum sum. Traverse only right or down. Example: starting index is 15 (left top) and ending index is 10 (bottom right) 15 25 30 45 25 60 70 75 10 O/P:15->45->70->75->10 sum is 215

c++ program to print string along the diagonals of the matrix.