Hi guys,I was interesting,how to write a function,to determine the nearest square number that is equal or greater to the length of the string( for example 16 is the next square number after 13)

I don't even know what is the mechanism of this function:-/

Write a square function,

#include <climits>
#include <cmath>

using namespace std;

int square(int q)
{}
int main()
{
    int number, min = INT_MAX;
    for(int i = 1; i < number/2; ++i) {
        if((temp_min = abs(square(i) - number)) <= min) {
            min = temp_min;
            nearest_s = i;
        }
    }
    cout << nearest_s * nearest_s << endl;
}

Do something like this :

int nearSqrt(int num){
 int n = sqrt(num);
 return n*n;
}

That returns the nearest square number. For it to be greater than num,you need to return (n+1)*(n+1);

A square number is , a number that can be wrote x^2.For Ex 4^2=16;
How to check this?
1.Read the number , then do n=sqrt(number);
What does "sqrt" do?It simply returns Square root of x.Click me for more information
! Do not forget to use #include <math.h>
2.Show the Answer . pow (nr+1,2);
What does "pow" do ? Read Me.

Problem Solved :

#include <iostream>
#include <math.h>

using namespace std;

double Next_pow(double num){
     double n=sqrt(num)+1;
     return pow(n,2);
}
double number;

int main(){
    cin>>number;
    cout<<Next_pow(number);
}
commented: Did you not see my post? -1

even wondering why people use - rep .. I even explained this guy how to do it , but why only me .. The other 2 people told him 2..

commented: Here have some if it makes you feel better. +5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.