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 string along the diagonals of the matrix.

Kollywood Game

C program to print the following Pattern