C++ arrays select square number and make new vector

Posted by John Smith on Stack Overflow See other posts from Stack Overflow or by John Smith
Published on 2012-12-08T16:39:02Z Indexed on 2012/12/08 17:03 UTC
Read the original article Hit count: 198

Filed under:
|
|

I have to see which of the following from a vector is a square number then make another vector with only the square numbers For example: (4,15,6,25,7,81) the second will be (4,25,81)

4,25,81 because 2x2=4 5x5=25 and 9x9=81

I started like this:

{

    int A[100],n,r,i;
    cout<<"Number of elements=";
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cout<<"A["<<i<<"]=";
        cin>>A[i];
    }
    for(i=1;i<=n;i++)
        {
            r=sqrt(A[i]);
            if(r*r==A[i])


    }

return 0;

}

but I am not really sure how to continue

© Stack Overflow or respective owner

Related posts about c++

Related posts about arrays